2104_Let the Balloon Rise

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count 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 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.


Output

For 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


Author: WU, Jiazhi

Source: Zhejiang Provincial Programming Contest 2004

×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××

//找出颜色最多的并输出该颜色
#include<iostream>
#include<string>
using namespace std;
struct balloon
{
string color;
};
int main()
{
balloon ba1[1000];//存放输入数据
balloon ba2[1000];//按原有顺序存放不同颜色的数据个一个
int count[1000]={0};//各颜色出现的个数,与ba2中颜色出现顺序对应
int num;
int i,j;
int ba;
int max,index;
bool flag;
while(cin>>num&&num)
{
ba=0;
for(i=0;i!=num;i++)
{   
flag=true;
cin>>ba1[i].color;
for(j=0;j!=i;j++)
if(ba2[j].color==ba1[i].color)//判断读取的颜色在前面是否已经输入
{
count[j]++;//是:对应颜色的count+1
flag=false;
}
if(flag)//否:将该颜色加入到ba2
ba2[ba++].color=ba1[i].color;
}
max=0;
for(i=0;i!=ba;i++)
{
if(count[i]>max)//找出颜色数最多的
{
max=count[i];//标记该颜色的数量
index=i;//记录其下标
}
}
cout<<ba2[index].color<<endl;
for(i=0;i!=num;++i)//initialize for the next(very important)
count[i]=0;
}
return 0;
}







你可能感兴趣的:(2104_Let the Balloon Rise)