【HDOJ】1048 The Hardest Problem Ever
其实这道题目可以没那么水。用状态机做的。
1 #include <stdio.h> 2 #include <string.h> 3 4 #define STARTSTR "START" 5 #define ENDSTR "END" 6 #define ENDINSTR "ENDOFINPUT" 7 #define ALPNUM 26 8 #define MAXNUM 105 9 10 char cipher[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 11 char plain[] = "VWXYZABCDEFGHIJKLMNOPQRSTU"; 12 char buf[MAXNUM]; 13 14 typedef enum { 15 en_start = 0, 16 en_cont, 17 en_end, 18 en_endin 19 } input_em; 20 21 int main() { 22 int i; 23 input_em st=en_start; // 0:begin, 1:end, -1 eof 24 25 while (gets(buf) != NULL) { 26 if (st==en_start && strcmp(buf, STARTSTR) == 0) { 27 st = en_cont; 28 continue; 29 } 30 if (st==en_end && strcmp(buf, ENDSTR) == 0) { 31 st = en_start; 32 continue; 33 } 34 if (st==en_start && strcmp(buf, ENDINSTR) == 0) { 35 st = en_endin; 36 break; 37 } 38 if (st==en_cont) { 39 for (i=0; i<strlen(buf); ++i) 40 if (buf[i]>='A' && buf[i]<='Z') 41 printf("%c", plain[buf[i]-'A']); 42 else 43 printf("%c", buf[i]); 44 printf("\n"); 45 st = en_end; 46 } 47 } 48 49 return 0; 50 }