This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
5 green red blue red red 3 pink orange pink 0
red pink
输入一定数量个字符串,求字符串出现次数最多的字符串
注意:
本程序用c语言的库函数来strcmp来比较两个字符串是否相等。
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
int n,i,j,k,maxnum;
int num[1000];
char color[1000][16];
while(scanf("%d",&n),n)
{
scanf("%s",color[0]);
num[0]=1;
for(i=1;i<n;i++)
{
num[i]=1;
scanf("%s",color[i]);
for(j=0;j<i-1;j++)
{
if(strcmp(color[j],color[i])==0)
num[i]++;
}
}
maxnum=num[0];
k=0;
for(i=1;i<n;i++)
{
if(maxnum<num[i])
{
maxnum=num[i];
k=i;
}
}
printf("%s\n",color[k]);
}
return 0;
}