5.1.1 WRTYU http://poj.grids.cn/practice/2538/
View Code
1 # include <stdio.h> 2 3 char *s = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./"; 4 5 int main () { 6 7 char c; 8 while ((c = getchar()) != EOF) { 9 int i; 10 for (i = 1; s[i] && s[i]!=c; ++i); 11 if (s[i]) putchar(s[i-1]); 12 else putchar(c); 13 } 14 15 return 0; 16 }
5.1.2 TeX括号 http://poj.grids.cn/practice/1488/
View Code
1 # include <stdio.h> 2 3 int main () { 4 5 char c; 6 bool p = true; 7 while ((c = getchar()) != EOF) { 8 if (c == '"') { 9 printf("%s", p ? "``" : "''"); 10 p = !p; 11 } 12 else putchar(c); 13 } 14 15 return 0; 16 }
5.1.3 周期串 http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=19496
View Code
1 # include <stdio.h> 2 # include <string.h> 3 4 int main () 5 { 6 7 int len, n; 8 char str[100]; 9 scanf("%d", &n); 10 while (n--) 11 { 12 scanf("%s", str); 13 len = strlen(str); 14 int i, j; 15 for (i = 1; i <= len; ++i) 16 { 17 if (len%i == 0) 18 { 19 int ok = 1; 20 for (j = i; j < len; ++j) 21 { 22 if (str[j] != str[j%i]) 23 { 24 ok = 0; 25 break; 26 } 27 } 28 if (ok) 29 { 30 printf("%d\n", i); 31 if (n) puts(""); 32 break; 33 } 34 } 35 } 36 } 37 38 return 0; 39 }