标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 using namespace std; 5 6 char key1[9][5]={" ","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"}; 7 char key2[28]={" QWERTYUIOPASDFGHJKLZXCVBNM"}; 8 9 int main() 10 { 11 int i,j,k,t; 12 char s[1005]; 13 char temp[1005]; 14 char ans[1005]; 15 while(scanf("%s",s)!=EOF) 16 { 17 int len=strlen(s); 18 for(j=0,i=0;i<len;i+=2) 19 temp[j++]=key1[s[i]-‘0‘-1][s[i+1]-‘0‘-1]; 20 temp[j]=‘\0‘; 21 t=0; 22 for(i=0;i<j;i++) 23 { 24 for(k=1;k<27;k++) 25 if(temp[i]==key2[k]) 26 ans[t++]=(char)(k+‘A‘-1); 27 } 28 ans[t]=‘\0‘; 29 for(j=0,i=ceil((double)t/2);i<t;i++) 30 temp[j++]=ans[i]; 31 temp[j]=‘\0‘; 32 for(i=ceil((double)t/2)-1;i>0;i--) 33 ans[i*2]=ans[i]; 34 for(j=0,i=1;i<t;i+=2) 35 ans[i]=temp[j++]; 36 ans[t]==‘\0‘; 37 strrev(ans); 38 printf("%s\n",ans); 39 } 40 return 0; 41 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4676545.html