|
本来是一道水题,模拟的。但是我当时把一个int变量定义成char型的,结果是死活都调试不出来!一直WA 。最后还是自己检查出来了。
1#include <stdio.h> 2#include <memory.h> 3#include <stdlib.h> 4#define DEBUG 1 5const int N = 1005 ; 6 7int main() 8{ 9 #if DEBUG 10 freopen("C:\\Documents and Settings\\Administrator\\桌面\\in.txt","r",stdin); 11 freopen("C:\\Documents and Settings\\Administrator\\桌面\\out.txt","w",stdout); 12 #endif 13 14 char a[N], b[N], ans[N], *p, aaa[N] ; 15 int i, j, k, num, geshu ; 16 double nn ; 17 //预先把数据写好 18 for( k=0,i=20; i<=70; i+=10,++k ){ 19 for( j=1; j<=3; ++j,++k ) 20 b[i+j] = k+'A' ; 21 --k ; 22 } 23 b[74] = 'S' ; 24 for( k=19,i=80; i<=90; i+=10,++k ){ 25 for( j=1; j<=3; ++j,++k ) 26 b[i+j] = k+'A' ; 27 --k ; 28 } 29 b[94] = 'Z' ; 30 while( scanf("%s", a ) != EOF ){ 31 memset(ans,0,sizeof(ans)); 32 memset(aaa,0,sizeof(aaa)); 33 p = a ; 34 for( i=0; *p; ++i ){ 35 num = *p-'0' ; 36 ++p ; 37 num = num*10 + *p-'0' ; 38 ans[i] = b[num] ; 39 ++p ; 40 } 41 ans[i] = '\0' ; 42 geshu = i ; 43 for( j=0; j<=geshu; ++j ){ 44 switch ( ans[j] ){ 45 case 'Q': ans[j] = 'A' ;break ; 46 case 'W': ans[j] = 'B' ;break ; 47 case 'E': ans[j] = 'C' ;break ; 48 case 'R': ans[j] = 'D' ;break ; 49 case 'T': ans[j] = 'E' ;break ; 50 case 'Y': ans[j] = 'F' ;break ; 51 case 'U': ans[j] = 'G' ;break ; 52 case 'I': ans[j] = 'H' ;break ; 53 case 'O': ans[j] = 'I' ;break ; 54 case 'P': ans[j] = 'J' ;break ; 55 case 'A': ans[j] = 'K' ;break ; 56 case 'S': ans[j] = 'L' ;break ; 57 case 'D': ans[j] = 'M' ;break ; 58 case 'F': ans[j] = 'N' ;break ; 59 case 'G': ans[j] = 'O' ;break ; 60 case 'H': ans[j] = 'P' ;break ; 61 case 'J': ans[j] = 'Q' ;break ; 62 case 'K': ans[j] = 'R' ;break ; 63 case 'L': ans[j] = 'S' ;break ; 64 case 'Z': ans[j] = 'T' ;break ; 65 case 'X': ans[j] = 'U' ;break ; 66 case 'C': ans[j] = 'V' ;break ; 67 case 'V': ans[j] = 'W' ;break ; 68 case 'B': ans[j] = 'X' ;break ; 69 case 'N': ans[j] = 'Y' ;break ; 70 case 'M': ans[j] = 'Z' ;break ; 71 case '\0': ans[j] = '\0' ;break ; 72 } 73 } 74 75 //考虑奇偶的问题 76 nn = geshu/(double)2 ; 77 geshu /= 2 ; 78 if( geshu != nn ) 79 ++geshu ; 80 //归并 81 for( i=0,j=0; i<geshu; ++i,j+=2 ){ 82 aaa[j] = ans[i] ; 83 aaa[j+1] = ans[i+geshu] ; 84 } 85 aaa[j]='\0'; 86 //逆序输出 87 for( i=0; aaa[i]; ++i ) 88 ; 89 for( j=i-1; j>=0; --j ) 90 printf("%c", aaa[j] ) ; 91 printf("\n") ; 92 memset(a,0,sizeof(a)); 93 } 94 return 0 ; 95} 96
|