hdu 1004 Let the balloon rise
2015-08-07 10:23
357 查看
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 90023 Accepted Submission(s): 34158
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
5
green
red
blue
red
red
3
pink
orange
pink
0
[align=left]Sample Output[/align]
red
pink
[align=left]Author[/align]
WU, Jiazhi
[align=left]Source[/align]
ZJCPC2004
//此题题意:让你求出给出一组数据中颜色气球类最多的一种,并输出。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{ int n;
char s[1001][16];
int num[1001];
while(scanf("%d",&n)!=EOF,n)
{
memset(num,0,sizeof(num));//数组清零;
for(int i=0;i<n;i++)
{
scanf("%s",s[i]);
for(int j=0;j<i-1;j++)
{
if(strcmp(s[i],s[j])==0)//比较
num[j]++;
}
}
int maxi=0,t=0;
for(int i=0;i<n;i++)//判断
{
if(num[i]>maxi)
{maxi=num[i];
t=i;
}
}
cout<<s[t]<<endl;
}
return 0;
}
相关文章推荐
- 动易2006序列号破解算法公布
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- 超大数据量存储常用数据库分表分库算法总结
- C#数据结构与算法揭秘二
- C#冒泡法排序算法实例分析
- 算法练习之从String.indexOf的模拟实现开始
- C#算法之关于大牛生小牛的问题
- C#实现的算24点游戏算法实例分析
- c语言实现的带通配符匹配算法
- 浅析STL中的常用算法
- 算法之排列算法与组合算法详解
- C++实现一维向量旋转算法
- Ruby实现的合并排序算法
- C#折半插入排序算法实现方法
- 基于C++实现的各种内部排序算法汇总
- C++线性时间的排序算法分析
- C++实现汉诺塔算法经典实例
- PHP实现克鲁斯卡尔算法实例解析
- C#获取关键字附近文字算法实例