Let the Balloon Rise
2013-11-27 08:35
337 查看
ProblemDescription
Contesttimeagain!Howexciteditistoseeballoonsfloatingaround.Buttotellyouasecret,thejudges'favoritetimeisguessingthemostpopularproblem.Whenthecontestisover,theywillcounttheballoonsofeachcolorandfindtheresult.
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]
相关文章推荐
- VC调试技巧
- 命令使用技巧
- HashMap和Hashtable的区别
- 避免代码冗余,使用接口和泛型重构Java代码
- VC调试器高级应用----系统函数,DLL段点
- sublime快捷键
- 如何高效使用SQLite .net (C#)
- LinkedList和ArrayList的区别
- 权限管理 (二) 实现中几个问题
- 权限管理 (二) 实现中几个问题
- Java 面试题问与答:编译时与运行时
- 《ASP.NET1200例》<ItemTemplate>标签在html里面有什么具体的作用
- Java集合框架面试问题集锦
- mysql中my.cnf的一个配置文件
- vi编辑器
- 程序员必知8大排序3大查找(三)
- 程序员必知8大排序3大查找(二)
- mfc改变鼠标形状
- 免费的编程中文书籍索引
- codeforces Round #215 div2 题解