手机键盘

问题描述:

 

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define MAXN 50
 4 char word[MAXN],*p,*keybd[8]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
 5 int main()
 6 {
 7     fgets(word,sizeof(word),stdin);
 8     int i=0,n=strlen(word);
 9     for(i;i<n-1;i++) //i<n-1是因为从stdin读入时,最后一个'\n'也读入了,这里不用管
10     {
11         for(int j=0;j<8;j++)
12         {
13             if((p=strchr(keybd[j],word[i]))!=NULL)
14             {
15                 printf("%c%d",word[i],p-keybd[j]+1);
16             }
17         }
18     }
19     printf("\n");
20     return 0;
21 }

运行结果:

 

posted @ 2020-04-05 18:30  kakusan  阅读(154)  评论(0编辑  收藏  举报