I LOVE YOU HELLO WORLD 444 0 555 666 888 33 0 999 666 88 44 33 555 555 666 0 9 666 777 555 3
444 0 555 666 888 33 0 999 666 88 44 33 555 555 666 0 9 666 777 555 3 I LOVE YOU HELLO WORLD
直接模擬!
AC碼:
#include#include int main() { int i,a,b,j,count; char str[1005],ch; while(gets(str)) { if((str[0]>='A')&&(str[0]<='Z')||str[0]==' ') { for(i=0;str[i]!='\0';i++) { if(str[i]==' ') { printf("0 "); } else if(str[i]>='A'&&str[i]<='R') { a=(str[i]-'A')%3+1;// a為按鍵次數 b=(str[i]-'A')/3+2;// b為按的數字 for(j=1;j<=a;j++) printf("%d",b); printf(" "); } else if(str[i]=='S') printf("7777 "); else if(str[i]>='T'&&str[i]<='Y') { a=(str[i]-'T')%3+1; // a為按鍵次數 b=(str[i]-'T')/3+8; // b為按的數字 for(j=1;j<=a;j++) printf("%d",b); printf(" "); } else if(str[i]=='Z') printf("9999 "); } printf("\n"); } else { for(i=0;str[i]!='\0';i++) { if(str[i]==' ') continue; if(str[i]=='0') printf(" "); if(str[i]>='2'&&str[i]<='7') { count=0; a=str[i]-'0'; while(str[i]>='0'&&str[i]<='7') { count++; i++; } ch=(a-2)*3+'A'+(count-1); printf("%c",ch); } else if(str[i]>='8'&&str[i]<='9') { count=0; a=str[i]-'8'; while(str[i]>='8'&&str[i]<='9') { count++; i++; } ch=a*3+'T'+(count-1); printf("%c",ch); } } printf("\n"); } memset(str,0,sizeof(str)); } return 0; }