zrq495
www.zrq495.com

1A,呵呵。

注意不区分大小写,如果单词重复也要算的,还有单词要合法,就是哲句话“A keyword ``occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.”

代码如下:

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 char keyword[100][100];
 5 int n, m;
 6 
 7 int search(char str[])
 8 {
 9     int i, k, slen=strlen(str);
10     char s[100];
11     int j=0, count=0;
12     for (i=0; i<slen; i++)
13     {
14         if (str[i]>='a' && str[i] <= 'z')
15         {
16             s[j]=str[i];
17             j++;
18         }
19         else
20         {
21             s[j]=0;
22             j=0;
23             for (k=0; k<n; k++)
24             {
25                 if (!strcmp(s, keyword[k]))
26                     count++;
27             }
28         }
29     }
30     return count;
31 }
32 
33 int main()
34 {
35     int i, count[100], num=1, max, j, slen;
36     char str[100], s[100][100];
37     while(scanf("%d%d%*c", &n, &m) != EOF)
38     {
39         for (i=0; i<n; i++)
40         {
41             gets(keyword[i]);
42             for (j=0; j<strlen(keyword[i]); j++)
43                 if (keyword[i][j] >= 'A' && keyword[i][j] <='Z')
44                     keyword[i][j]+=32;
45         }
46         for (i=0; i<m; i++)
47         {
48             gets(str);
49             slen=strlen(str);
50             strcpy(s[i], str);
51             for (j=0; j<slen; j++)
52                 if (str[j] >='A' && str[j] <='Z')
53                     str[j]+=32;
54             count[i]=search(str);
55         }
56         printf("Excuse Set #%d\n", num);
57         num++;
58         max=0;
59         for (i=0; i<m; i++)
60             if (max <= count[i])
61                 max=count[i];
62         for (i=0; i<m; i++)
63             if (max == count[i])
64                 puts(s[i]);
65         printf("\n");
66     }
67     return 0;
68 }
posted on 2012-05-31 17:17  zrq495  阅读(339)  评论(0编辑  收藏  举报