nyoj-685-查找字符串

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<string.h>
 4 char a[100001][20],ch[20];
 5 int num[100001];
 6 int main()
 7 {
 8     int n,t,m,top,i,j;
 9     while(scanf("%d",&n)!=EOF)
10     {
11         while (n--)
12         {
13             scanf("%d%d",&t,&m);
14             top=0;
15             fflush(stdin);
16             for (i=0;i<t;i++)
17             {
18                 scanf("%s",ch);
19                 int flag=0;
20                 for(j=0;j<top;j++)
21                 {
22                     if(!strcmp(ch,a[j]))
23                     {
24                         num[j]++;
25                         flag=1;
26                         break;
27                     }
28                 }
29                 if(flag==0)
30                 {
31                     strcpy(a[top],ch);
32                     num[top]=1;
33                     top++;
34                 }
35             }
36             for(i=0;i<m;i++)
37             {
38                 scanf("%s",ch);
39                 int flag=0;
40                 for(j=0;j<top;j++)
41                 {
42                     if(!strcmp(ch,a[j]))
43                     {
44                         printf("%d
",num[j]);
45                         flag=1;
46                         break;
47                     }
48                 }
49                 if(!flag)
50                 printf("0
");
51             }
52             //for(i=0;i<top;i++)
53             //{
54                 //puts(a[i]);
55                 //printf("%d
",num[i]);
56             //}
57         }
58     }
59     return 0;
60 }
原文地址:https://www.cnblogs.com/nylg-haozi/p/3187592.html