1004 Let the Balloon Rise(水题)

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 char s[1002][20];
 4 char ss[1002][20];
 5 int k[1002];
 6 int main()
 7 {
 8     int i,n,j,x,w;
 9     while(scanf("%d",&n)!=EOF&&n)
10     {
11         scanf("%s",s[0]);
12         getchar();
13         w=0;
14         strcpy(ss[0],s[0]);
15         k[0]=1;
16         for(i=1;i<n;i++)
17         {
18             scanf("%s",s[i]);
19             getchar();
20             for(j=0;j<=w;j++)
21             {
22                 int r=strcmp(ss[j],s[i]);
23 
24                 if(r==0)
25                 {
26                     k[j]++;
27                     break;
28                 }
29             }
30             if(j==w+1)
31             {
32                 w++;
33                 strcpy(ss[w],s[i]);
34                 k[w]=1;
35             }
36         }
37         int max=-1;
38         for(i=0;i<=w;i++)
39         {
40             if(max<k[i])
41             {
42                 max=k[i];
43                 x=i;
44             }
45         }
46         printf("%s\n",ss[x]);
47     }
48     return 0;
49 }
原文地址:https://www.cnblogs.com/ACshasow/p/2764118.html