【HDOJ】1606 Excuses, Excuses!
简单字符串。
1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXLEN 105 5 #define MAXN 25 6 7 char keys[MAXN][MAXN]; 8 char lines[MAXN][MAXLEN]; 9 int nums[MAXN]; 10 11 int main() { 12 int case_n = 0; 13 int n, m, max; 14 int i, j, k, v; 15 char tmp[MAXLEN]; 16 17 while (scanf("%d %d",&n,&m) != EOF) { 18 for (i=0; i<n; ++i) 19 scanf("%s", keys[i]); 20 getchar(); 21 memset(nums, 0, sizeof(nums)); 22 max = -1; 23 for (i=0; i<m; ++i) { 24 gets(lines[i]); 25 v = 0; 26 for (j=0; j<strlen(lines[i]); ++j) { 27 if (lines[i][j]>='A' && lines[i][j]<='Z') { 28 tmp[v++] = lines[i][j]-'A'+'a'; 29 } else if (lines[i][j]>='a' && lines[i][j]<='z') { 30 tmp[v++] = lines[i][j]; 31 } else { 32 if (v) { 33 tmp[v++] = '\0'; 34 for (k=0; k<n; ++k) { 35 if (strcmp(tmp, keys[k]) == 0) 36 ++nums[i]; 37 } 38 } 39 v = 0; 40 } 41 } 42 if (v) { 43 tmp[v++] = '\0'; 44 for (k=0; k<n; ++k) { 45 if (strcmp(tmp, keys[k]) == 0) 46 ++nums[i]; 47 } 48 } 49 if (nums[i] > max) max = nums[i]; 50 } 51 printf("Excuse Set #%d\n", ++case_n); 52 for (i=0; i<n; ++i) { 53 if (nums[i] == max) 54 printf("%s\n", lines[i]); 55 } 56 printf("\n"); 57 } 58 59 return 0; 60 }