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 Descriptionwelcome to 2006 ' 4 Computer College programming contest!
Specially, I give my best regards to all freshmen! You is the future of HDU acm! And now, I must the that ACM problems is always don't so easy, but, except this one ... ha-ha!
Give 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 are 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.
Inputinput file contains multiple test cases. There is a positive integer n (n<100) on the first line, which means the number of test cases, and then n 32-bit intege RS follow.
Outputfor Each test case, you should the output its reverse number, one case per line.
Sample Input
312-121200
Sample Output
21-212100
Authorlcy
Source
HDU 2006-4 Programming Contest
It's a quick and convenient thing to do with string .... ~ ~ ~, the question should be submitted to 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;}
Hangzhou Electric HDU 1266 Reverse number