HDU1266 字符串逆转

只要注意记录的 0 的个数就行

水~~

View Code
 1 /*
 2 字符串逆转
 3 */
 4 #include<stdio.h>
 5 #include<string.h>
 6 #include<stdlib.h>
 7 #include<algorithm>
 8 #include<iostream>
 9 #include<queue>
10 //#include<map>
11 #include<math.h>
12 using namespace std;
13 typedef long long ll;
14 //typedef __int64 int64;
15 const int maxn = 105;
16 const int inf = 0x7fffffff;
17 const int pi=acos(-1.0);
18 char a[ 1005 ],temp[ 1005 ];
19 int main(){
20     int ca;
21     scanf("%d",&ca);
22     getchar();
23     while( ca-- ){
24         gets( a );
25         int len=strlen( a );
26         int s=0;
27         if( a[ s ]=='-' ){
28             printf("-");
29             s++;
30         }
31         int cnt=0;
32         int i;
33         for( i=len-1;i>=s;i-- ){
34             if( a[ i ]=='0' ){
35                 cnt++;
36             }
37             else
38                 break;
39         }
40         for( ;i>=s;i-- ){
41             printf("%c",a[ i ]);
42         }
43         for( int j=0;j<cnt;j++ )
44             printf("0");
45         printf("\n");
46     }
47     return 0;
48 }
keep moving...
原文地址:https://www.cnblogs.com/xxx0624/p/2943494.html