问题:
http://acm.pku.edu.cn/JudgeOnline/problem?id=1298思路:
简单题,不需要任何"算法"
这里之所以记录的原因是,我用scanf进行输入,虽然AC,不过比较繁琐(scanf会因为读到空白符而结束,与题意不符)
网上看到"史上最精髓的gets"呵呵,不禁赞叹...
代码:
"scanf version"
1 #define ENDALL "ENDOFINPUT"
2 #define ENDEACH "END"
3 #define MAX_LEN 250
4 const char cipher[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
5 const char plain[] = "VWXYZABCDEFGHIJKLMNOPQRSTU";
6 char msg[MAX_LEN];
7
8 void
9 translate(char *msg)
10 {
11 int i, len=strlen(msg);
12 for(i=0; i<len; i++)
13 if(msg[i]>='A' && msg[i]<='Z')
14 msg[i] = plain[msg[i]-'A'];
15 printf("%s ", msg);
16 }
17
18 int
19 main(int argc, char **argv)
20 {
21 char temp[15];
22 while(scanf("%s", temp)!=EOF) {
23 if(strcmp(temp, ENDALL)==0)
24 break;
25 while(scanf("%s", msg) && strcmp(msg, ENDEACH)!=0)
26 translate(msg);
27 printf("\n");
28 }
29 return 0;
30 }
"gets version"
1 #define ENDALL "ENDOFINPUT"
2 #define MAX_LEN 250
3 const char cipher[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4 const char plain[] = "VWXYZABCDEFGHIJKLMNOPQRSTU";
5 char msg[MAX_LEN];
6
7 void
8 translate(char *msg)
9 {
10 int i, len=strlen(msg);
11 for(i=0; i<len; i++)
12 if(msg[i]>='A' && msg[i]<='Z')
13 msg[i] = plain[msg[i]-'A'];
14 printf("%s\n", msg);
15 }
16
17 int
18 main(int argc, char **argv)
19 {
20 char temp[15];
21 while(gets(temp)!=EOF) {
22 if(strcmp(temp, ENDALL)==0)
23 break;
24 gets(msg);
25 translate(msg);
26 gets(temp);
27 }
28 return 0;
29 }