Problem Description
Contest time again! How excited it isto see balloons floating around. But to tell you a secret, the judges' favoritetime is guessing the most popular problem. When the contest is over, they willcount the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
Input
Input contains multiple test cases.Each test case starts with a number N (0 < N <= 1000) -- the total numberof balloons distributed. The next N lines contain one color each. The color ofa balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to beprocessed.
Output
For each case, print the color ofballoon for the most popular problem on a single line. It is guaranteed thatthere is a unique solution for each test case.
较简单的题目
以下代码:
#include<stdio.h>
#include<string.h>
intmain()
{
char color[1001][16];
int i, j, n, temp;
while(scanf("%d", &n)&& n != 0){
getchar();
int num[1006] = {0}; //用于存储当前项的个数
for (i = 0; i < n; i++)
gets(color[i]);
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (strcmp(color[i],color[j]) == 0)
num[i]++;
}
}
temp = 0; //假设当前最大为num[0]
for (i = 1; i < n; i++)
{
if (num[temp] < num[i])
temp = i;
}
printf("%s\n",color[temp]);
}
}