电子科大POJ "敲错键盘"



C-sources:

 1 #include<stdio.h>
 2 #define N 20
 3 int main()
 4 {
 5     int i,j;
 6     char RightKeyBoardR[34]={'Q','W','E','R','T','Y','U','I','O','P','[',']',
 7                         'A','S','D','F','G','H','J','K','L',';','\'','\\',
 8                         'Z','X','C','V','B','N','M',',','.','/'};
 9 
10     char *WrongInput=(char*)malloc(N*sizeof(char));
11     for(i=0;i<N;i++)
12         WrongInput[i]='\0';
13 
14     gets(WrongInput);
15 
16 
17 
18     int len=strlen(WrongInput);
19     char *MemInput=(char*)malloc((len+1)*sizeof(char));
20 
21     strncpy(MemInput,WrongInput,len+1);
22 
23     for(i=0;i<len;i++)
24         for(j=0;j<34;j++)
25     {
26         if(MemInput[i]!=' ')
27         {
28             if(MemInput[i]==RightKeyBoardR[j])
29                 MemInput[i]=RightKeyBoardR[j-1];
30         }
31 
32     }
33 
34 
35         printf("%s",MemInput);
36 
37     return 0;
38 }
posted @ 2014-07-04 11:37  vpoet  阅读(182)  评论(0编辑  收藏  举报