HDU1062
字符串的翻转
注意一些特殊的情况即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 字符翻转 3 注意这种情况:_ _ ab_ _ _cc_ _ 4 "_"都是要输出的 5 6 */ 7 #include<stdio.h> 8 #include<string.h> 9 const int maxn = 1105; 10 char s[ maxn ]; 11 int main(){ 12 int n; 13 scanf("%d",&n); 14 getchar(); 15 while( n-- ){ 16 int len; 17 gets( s ); 18 //printf("s:%s\n",s); 19 len=strlen( s ); 20 /* 21 for( int i=len-1;i>=0;i-- ) 22 if( s[ i ]==' ') len--; 23 else break; 24 */ 25 int st,e; 26 int flag=-1; 27 for( int i=0;i<len;i++ ){ 28 if( i>=len ) break; 29 if( s[ i ]==' ' ) {printf(" ");continue;} 30 st=i; 31 for( int j=i;j<len;j++ ){ 32 if( s[ j ]==' ' ){ 33 e=j-1; 34 for( int k=e;k>=st;k-- ) printf("%c",s[ k ]); 35 printf(" "); 36 i=j; 37 break; 38 } 39 if( j==len-1 ){ 40 e=j; 41 for( int k=e;k>=st;k-- ) printf("%c",s[ k ]); 42 printf("\n"); 43 flag=1; 44 i=j; 45 break; 46 } 47 } 48 } 49 if( flag==-1 ) printf("\n"); 50 } 51 return 0; 52 }
keep moving...