Reverse number
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 5052 accepted submission (s): 2352
Problem descriptionwelcome 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, cannot 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.
Inputinput 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.
Outputfor each test case, You shoshould output its reverse number, one case per line.
Sample input3 12-121200
Sample Output21-212100
# Include <stdio. h> # include <string. h> # define maxn 10000 char a [maxn]; // defines the character array int main () {int t, n, I, Len; int K; scanf ("% d", & T); While (t --) {scanf ("% s", & A); // input string Len = strlen (); for (k = len-1; k> = 0; k --) {if (a [k]! = '0') // filtering, non-zero part A [k] Break;} if (a [0] = '-') {printf ("-"); for (I = K; I> = 1; I --) // save K in printf ("% C", a [I]); // reverse for (I = k + 1; I <Len; I ++) printf ("0");} else {for (I = K; I> = 0; I --) printf ("% C", a [I]); for (I = k + 1; I <Len; I ++) printf ("0 ");} printf ("\ n");} return 0 ;}
View code
# Include <stdio. h>
# Include <string. h>
# Define maxn10000
Char A [maxn]; // defines the character array
Int main ()
{
Int t, n, I, Len;
Int K;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% s", & A); // enter the string
Len = strlen ();
For (k = len-1; k> = 0; k --)
{
If (A [k]! = '0') // filter, non-zero-bit part A [k]
Break;
}
If (A [0] = '-')
{
Printf ("-");
For (I = K; I> = 1; I --) // save K in I
Printf ("% C", a [I]); // reverse
For (I = k + 1; I <Len; I ++)
Printf ("0 ");
}
Else
{
For (I = K; I> = 0; I --)
Printf ("% C", a [I]);
For (I = k + 1; I <Len; I ++)
Printf ("0 ");
}
Printf ("\ n ");
}
Return 0;
}
#include<iostream>#include<string>using namespace std;int main(){ int n; cin>>n; string s; while(n--) { cin>>s; int begin = 0,end,i,j; if(s[0] == ‘-‘)begin = 1; while(s[begin] == ‘0‘)begin++; end = s.size()-1; while(s[end] == ‘0‘)end--; reverse(s.begin()+begin,s.begin()+end+1); cout<<s<<endl; } return 0;}
View code
# Include <iostream>
# Include <string>
Using namespace STD;
Int main ()
{
Int N;
Cin> N;
String S;
While (n --)
{
Cin> S;
Int begin = 0, end, I, j;
If (s [0] = '-') Begin = 1;
While (s [begin] = '0') Begin ++;
End = S. Size ()-1;
While (s [end] = '0') end --;
Reverse (S. Begin () + begin, S. Begin () + end + 1 );
Cout <S <Endl;
}
Return 0;
}