409 Excuses, Excuses!

哎,不要用库函数查找子串

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<ctype.h>
 4 int main()
 5 {
 6     int T = 1, m, n;
 7     while(scanf("%d%d",&m,&n) != EOF)
 8     {
 9         getchar();
10         int i, j, k, len, f[100] = {0}, temp = 0, r;
11         char s[100][100], st[100][100], _st[100][100], _s[100];
12         for(i = 0;i < m; i++)
13         {
14             gets(s[i]);
15             len = strlen(s[i]);
16             for(j = 0;j < len; j++)
17             {
18                 if(isalpha(s[i][j]))
19             s[i][j] = toupper(s[i][j]);
20             }
21         }
22         for(i = 0;i < n; i++)
23         {
24             gets(st[i]);
25             strcpy(_st[i],st[i]);
26             len = strlen(st[i]);
27             for(j = 0;j < len; j++)
28             {
29                 if(isalpha(st[i][j]))
30                     st[i][j] = toupper(st[i][j]);
31             }
32         }
33         k = 0;
34         int J = 0;
35         for(i = 0;i < n; i++)
36         {
37             //puts(st[i]);
38             int l = strlen(st[i]);
39             for(j = 0;j < l; j++)
40             {
41                 if(!((st[i][j]>='a'&&st[i][j]<='z')||(st[i][j]>='A'&&st[i][j]<='Z')))
42                 {
43                     _s[J] = '\0';
44                 //    puts(_s);
45                     J = -1;
46                     for(r = 0;r < m; r++)
47                     {
48                         if(strcmp(_s,s[r]) == 0)
49                             f[i]++;
50                     }
51                 }
52                 else
53                 _s[J] = st[i][j];
54                 J++;
55             }
56             if(f[i] > temp)
57                 temp = f[i];
58         }
59         printf("Excuse Set #%d\n",T++);
60         for(i = 0;i < n; i++)
61         {
62             if(f[i] == temp)
63                 printf("%s\n",_st[i]);
64         }
65         printf("\n");
66     }
67     return 0;
68 }
原文地址:https://www.cnblogs.com/SDUTYST/p/2526049.html