这道题多次不过,就是因为忘记在每次的n值输入之后,对计数的数组清零。。。。
#include"stdio.h"
#include"string.h"
main()
{
char s[1000][15],temp[15];
int i,j,n,change,max,m,k;
int count[1000];
while((scanf("%d",&n))!=EOF&&n!=0)
{
memset(count,0,1000);
getchar();//吸收输入n之后的回车符
m=0;
for(i=0;i<n;i++)
{
change=1;
gets(temp);
for(j=0;j<m;j++)
{
if(strcmp(temp,s[j])==0)
{
change=0;
count[j]++;
}
}
if(change)
{
m++;
strcpy(s[m-1],temp);
count[m-1]++;
}
}
for(i=0,max=0;i<m;i++)
{
if(count[i]>max)
{
max=count[i];
k=i;
}
}
printf("%s\n",s[k]);
}
return 0;
}