HDU:Let the Balloon Rise
来源:互联网 发布:有人招聘网络写手吗? 编辑:程序博客网 时间:2024/04/30 03:37
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 106055 Accepted Submission(s): 41041
Problem Description
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.
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.
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
5greenredblueredred3pinkorangepink0解题思路:1.每次输入一个字符串,就让它与数组中的字符串比较,如果发现相等的,就让数目加1,比较完毕后,让他与最大数目相比,如果大于最大数目,就更新mmax的值,并更新字符串answer(答案)的值。2.可以用映射去写,map(string,int)本人代码:#include<iostream>#include<string>using namespace std;int main(){int n,mmax,i,j,ccount; //n是单词个数,mmax是最大个数,i,j为循环变量,ccount用来计数string color[1003],answer; //color为字符串数组,answer用来存放答案的临时变量while(cin>>n){if(n==0) //n为0结束循环break;answer="0"; //answer赋初值"0"mmax=0; //最大值初始化为0for(i=0;i<n;i++) //依次输入单词{ccount=0; //每次输入一个新的单词,就将数量初始化为0cin>>color[i]; //输入单词for(j=0;j<=i;j++) //和当前字符串数组中的每一个字符串进行比较if(color[i]==color[j])ccount++; //发现相同的,数量自增1if(ccount>mmax) //如果数量比最大值大{mmax=ccount; //最大值被更新answer=color[i]; //答案也被更新}}cout<<answer<<endl; //最后输出答案即可}return 0;}他人代码:#include<iostream>#include<string>#include<map>#include<algorithm>using namespace std;int main(){string temp,answer; //临时变量,temp,answerint n,mmax;while(cin>>n&&n){mmax=0;map<string,int>m; //映射,while(n--){cin>>temp; //输入一个单词m[temp]++; //该单词数目自增1if(m[temp]>mmax) //更新数据{mmax=m[temp];answer=temp;}}cout<<answer<<endl; //输出结果}return 0;}
0 0
- hdu Let the Balloon Rise
- HDU Let the Balloon Rise
- HDU:Let the Balloon Rise
- Hdu Let the Balloon Rise
- Let the Balloon Rise HDU
- hdu Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004.Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- 重拾算法(三):求最大公约数的常用方法总结
- 第二周项目二 程序的多文件组织
- 网络流24题——圆桌问题
- Oracle位图例子
- 五大主流深度学习框架比较分析:MXNET是最好选择
- HDU:Let the Balloon Rise
- 51nod1006 最长公共子序列Lcs--打表+输出
- 金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出。
- Red Black Tree(红黑树)
- mvc 自带验证使用
- 1007. Maximum Subsequence Sum (25)
- Java培训之JavaBean规范
- [pySpark][note]Word Count Lab: Building a word count application
- http响应(笔记)