This year, they decide to leave this lovely job to you.
InputInput contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a 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 be processed.
OutputFor each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input
5 green red blue red red 3 pink orange pink 0
Sample Output
red pink
找颜色最多的输出
#include <stdio.h>
#include <string.h>
int main()
{
int n, i, j, a[1000]; // 用数组 a来记录 颜色出现的次数
char color[1000][15];
while( scanf("%d", &n) != 0)
{
if( n == 0)
break;
else
{
a[0] = 1;
scanf("%s", color[0]); //先输入第一个颜色
for(i = 1; i < n; i++)
{
a[i] = 1;
scanf("%s",color[i]); //输入第n个元素然后不断和前面的颜色进行比较有相同就 +1
for(j = 0; j < i; j++)
if(strcmp(color[i],color[j]) == 0) a[i] += 1;
}
int max = 0;
int t = 0;
for(i = 1;i < n;i++)
if( max < a[i]) //找出出现次数最多的颜色
{
max = a[i];
t = i;}
printf("%s\n",color[t]);
}
}
}