标签:
分析:用二维数组存放字符串,另外在比较count[i]的大小时,注意保留数组的下标。
#include<stdio.h>
#include<string.h>
char str[1010][16];
int count[1010];
int main()
{
int m;
while(scanf("%d",&m),m)
{
int i,j;
int max,k;
for(i=0;i<m;i++)
scanf("%s",str[i]);
memset(count,0,sizeof(count));
for(i=0;i<m;i++)
for(j=0;j<m;j++)
{
if(strcmp(str[i],str[j])==0)
{
count[i]++;
}
}
max=count[0];
k=0;
for(i=0;i<m;i++)
{
if(max<count[i])
{
max=count[i];
k=i;
}
}
printf("%s\n",str[k]);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Hdu oj 1004 Let the Balloon Rise
标签:
原文地址:http://blog.csdn.net/zm_11/article/details/47360497