K - Let the Balloon Rise
来源:互联网 发布:哈奇森效应 知乎 编辑:程序博客网 时间:2024/06/05 16:36
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
Sample Output
redpink
#include <iostream>#include <map>#pragma warning(disable:a786)#include <cstdio>using namespace std;map<string,int>m;int main(){ int n,i; string color; while(scanf("%d",&n)&& n) { m.clear(); for(i = 0; i < n; i++) { cin>>color; m[color]++; } map<string,int>::iterator it; string color2; int temp=0; for(it=m.begin();it!=m.end();it++) { if((*it).second>temp) { temp=(*it).second; color2=(*it).first; } } cout<<color2<<endl; } return 0;}题意就是要哪种颜色最受欢迎 就是出现次数最多用map第一个寸颜色 第二个存数量 循环着遍历 最后设置一个变量 来查这个最多的颜色
0 0
- K - Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the balloon rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- 我的C++开发工具链
- 宁为玉碎,不为瓦全
- PHP 表单批量操作时过滤ID值
- 0x3f3f3f3f...编程中无穷大常量的设置技巧.
- mac secureCRT保存密码
- K - Let the Balloon Rise
- 【再思考】1025. 反转链表 (25)
- java 堆和栈一般理解
- SASS 学习
- 【练习册】 2015-08-09 Dlist Queue Stack by python
- SVM支持向量机
- 【Unity基础知识之五】Unity3d-在Unity项目中使用Mono DLL(动态链接库)
- hdu 3336 Count the string KMP+DP
- Unity中md5,base64