您的位置:首页 > 其它

Let the Balloon Rise

2013-11-27 08:35 337 查看

ProblemDescription

Contesttimeagain!Howexciteditistoseeballoonsfloatingaround.Buttotellyouasecret,thejudges'favoritetimeisguessingthemostpopularproblem.Whenthecontestisover,theywillcounttheballoonsofeachcolorandfindthe
result.

Thisyear,theydecidetoleavethislovelyjobtoyou.

Input

Inputcontainsmultipletestcases.EachtestcasestartswithanumberN(0<N<=1000)--thetotalnumberofballoonsdistributed.ThenextNlinescontainonecoloreach.Thecolorofaballoonisastringofupto15lower-caseletters.

AtestcasewithN=0terminatestheinputandthistestcaseisnottobeprocessed.

Output

Foreachcase,printthecolorofballoonforthemostpopularproblemonasingleline.Itisguaranteedthatthereisauniquesolutionforeachtestcase.

SampleInput

5
green
red
blue
red
red
3
pink
orange
pink
0


SampleOutput

red
pink








[code]#include<iostream>

usingnamespacestd;

intmain()
{
intnum;
while(cin>>num)//输入有多少个气球
{
stringtemp;
inti,j;
intcount=0;//计数
intmax=0;//记录种类最多的气球的个数
if(num==0)break;//当输入0个气球时结束
stringcolor[num];//气球的名称
for(i=0;i<num;i++)//输入气球的颜色
cin>>color[i];
/*算法思想:从第一个气球开始与他自己和后面的气球比较,若相同
则计数*/
for(i=0;i<num;i++)
{
for(j=0;j<num;j++)
{
if(color[j]==color[i])
count++;
}
if(count>max)//一直保留最大的那个数
{
max=count;
temp=color[i];
}

count=0;

}

cout<<temp<<endl;

}
return0;
}



[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: