发短信
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
3
-
描述
-
下图是手机常用的九键英文输入法界面,如果要输入字母'A',我们只需要按一次数字键2,按键顺序记为2;如果要输入字母'B'的话,我们需要连续按两次数字键2,按键顺序记为22;同理:字母'C’需要连续按3次数字键2,按键顺序记为222。通过这种方法,我们用手机10多个键就能输入26个英文字母。现在你的任务是统计一段英文用手机输入的按键顺序,同样,你也要能把按键顺序翻译成相应的英文内容。为了使问题简化,我们假设内容只有大写英文字母和空格。
-
输入
-
有多组测试数据
每组测试数据占一行,有两种情况:
(1)短信内容(只含有若干个空格和大写字母,不超过1000个字符)
(2)短信按键顺序(只含有若干空格和数字,其中第一个肯定是数字,不超过1000个字符)
输出
-
对于每组测试数据:
如果是短信内容,输出每个字母的按键顺序,每个字母的按键顺序用空格隔开
如果是按键顺序,输出它代表的内容
样例输入
-
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<stdio.h> #include<string.h> 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; }
-
有多组测试数据