标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1756 Accepted Submission(s):
1056
#include<stdio.h> #include<string.h> #define MAX 1100 char s[MAX]; int a[30]; char str2[MAX]; char str5[MAX]; char str3[30]={"QWERTYUIOPASDFGHJKLZXCVBNM"}; char str4[30]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; char str1[20][5]={"\0","\0","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"}; char str6[MAX],str7[MAX]; int main() { int n,m,j,i,t,l1,l2,l3,l4; while(scanf("%s",s)!=EOF) { memset(a,0,sizeof(a)); memset(str2,‘\0‘,sizeof(str2)); memset(str5,‘\0‘,sizeof(str5)); memset(str6,‘\0‘,sizeof(str6)); memset(str7,‘\0‘,sizeof(str7)); l1=strlen(s); j=0; for(i=0;i<l1;i=i+2,j++) str2[j]=str1[s[i]-‘0‘][s[i+1]-‘1‘]; l2=strlen(str2); for(i=0;i<l2;i++) for(j=0;j<26;j++) { if(str2[i]==str3[j]) { a[i]=j; break; } } for(i=0;i<l2;i++) str5[i]=str4[a[i]]; int k=l2/2; j=0; if(l2&1) { for(i=l2-1;i>k;i--) str6[j++]=str5[i]; j=0; for(i=k;i>=0;i--) str7[j++]=str5[i]; } else { for(i=l2-1;i>=k;i--) str6[j++]=str5[i]; j=0; for(i=k-1;i>=0;i--) str7[j++]=str5[i]; } if(l2&1) for(i=0;i<=k;i++) { printf("%c",str7[i]); if(i==k) break; printf("%c",str6[i]); } else for(i=0;i<k;i++) { printf("%c",str6[i]); printf("%c",str7[i]); } printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4676149.html