杭电 HDU 1266 Reverse Number

Reverse Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5763    Accepted Submission(s): 2643

Problem Description

Welcome to 2006‘4 computer college programming contest!

Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM problems are always not so easy, but, except this one... Ha-Ha!

Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:

1. The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21;

2. The reverse number of a negative integer is negative, for example, reverse (-12) = -21;

3. The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.

Input

Input file contains multiple test cases. There is a positive integer n (n<100) in the first line, which means the number of test cases, and then n 32-bit integers follow.

Output

For each test case, you should output its reverse number, one case per line.

Sample Input

3
12
-12
1200

Sample Output

21
-21
2100

Author

lcy

Source

HDU 2006-4 Programming Contest

感觉用string做比较迅速方便啦…………~~~,这题就该一次提交ac之;

AC code:

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int T,n;string str;
	while(cin>>T)
	{

		for(int i=0;i<T;i++)
		{
			cin>>str;
			int len=str.size();int k=len-1;
			if(str[0]!='-')
			{
				for(int i=len-1;i>=0;i--)
					if(str[i]!='0')
					{
						k=i;
						break;
					}
					for(int j=k;j>=0;j--)
						cout<<str[j];
					for(int p=0;p<len-1-k;p++)
						cout<<0;
					cout<<endl;
			}
			else
			{
				str.erase(0,1);
				cout<<'-';
			for(int i=len-1-1;i>=0;i--)
					if(str[i]!='0')
					{
						k=i;
						break;
					}
					for(int j=k;j>=0;j--)
						cout<<str[j];
					for(int p=0;p<len-2-k;p++)
						cout<<0;
					cout<<endl;
			}
		}

	}
return 0;
}
	
时间: 2024-10-08 10:19:14

杭电 HDU 1266 Reverse Number的相关文章

HDU 1266 Reverse Number(字符串逆转 水题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1266 Problem Description Welcome to 2006'4 computer college programming contest! Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM proble

杭电 HDU ACM 1391 Number Steps

Number Steps Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4376    Accepted Submission(s): 2656 Problem Description Starting from point (0,0) on a plane, we have written all non-negative inte

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

杭电 HDU 1038 Biker&#39;s Trip Odometer

Biker's Trip Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4745    Accepted Submission(s): 3144 Problem Description Most bicycle speedometers work by using a Hall Effect sensor faste

杭电 HDU 1037 Keep on Truckin&#39;

Keep on Truckin' Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9881    Accepted Submission(s): 6859 Problem Description Boudreaux and Thibodeaux are on the road again . . . "Boudreaux, we hav

杭电 HDU ACM 1397 Goldbach&#39;s Conjecture

Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4976    Accepted Submission(s): 1901 Problem Description Goldbach's Conjecture: For any even number n greater than or equal

杭电 HDU ACM 5186 zhx&#39;s submissions

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1892    Accepted Submission(s): 507 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many

杭电 HDU ACM 1025 Constructing Roads In JGShining&#39;s Kingdom

Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17732    Accepted Submission(s): 5023 Problem Description JGShining's kingdom consists of 2n(n is no mo

杭电HDU ACM Uncle Tom&#39;s Inherited Land*(二分图匹配 建模)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2496    Accepted Submission(s): 1028 Special Judge Problem Description Your old uncle Tom inherited a piece of land f