【菜鸟做水题】: 杭电1004

#include"stdio.h"
#include "string.h"
typedef struct
{
char str[16];
int count;
}COLOR;
COLOR color[1001];
int main()
{
int n = 0;
char str_in[16] = "";
while(scanf("%d", &n) != EOF)
{
//getchar();
if(n == 0)
break;

int index = 0;
for(int i = 0; i < n; i++)
{
bool flag = false;
scanf("%s", str_in);
for(int j = 0; j < index; j++)
if(strcmp(str_in, color[j].str) == 0)
{
color[j].count++;
flag = true;
}
if(flag == false)
{
strcpy(color[index].str, str_in);
color[index++].count = 1;
}
}
int max = 0;
for( int i = 0; i < index; i++)
if(color[i].count > color[max].count)
max = i;
printf("%s\n", color[max].str);
}
return 0 ;
}

  

原文地址:https://www.cnblogs.com/VortexPiggy/p/2585084.html