Winter-1-E Let the Balloon Rise 解题报告及测试数据
Time Limit:1000MS Memory Limit:32768KB
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.
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.
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
5
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output
red
pink
以下是代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>//使用字典容器
#include <string>
using namespace std;
int main(){
int n,k,cnt[1005];
char str[100];
string t;
while(scanf("%d",&n)!=EOF && n){
map<string,int>ball;
map<string, int>::iterator it;
k=1;
for(int i=0;i<1005;cnt[i]=1,i++);
for(int i=0;i<n;i++){
scanf("%s",str);
t = str;
if(ball.count(t))cnt[ball[t]]++;//存在,数量加一
else ball[t]=k++;//不存在,将颜色映射为数字
}
int maxn=1;
for(int i=2;i<n;i++)
if(cnt[i]>cnt[maxn])maxn=i;
for(it = ball.begin();it!=ball.end();it++)
if(it->second == maxn){
cout << it->first<<endl;
break;
}
ball.clear();
}
}
Winter-1-E Let the Balloon Rise 解题报告及测试数据的更多相关文章
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- Spring-2-H Array Diversity(SPOJ AMR11H)解题报告及测试数据
Array Diversity Time Limit:404MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- Spring-2-J Goblin Wars(SPOJ AMR11J)解题报告及测试数据
Goblin Wars Time Limit:432MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Th ...
- Spring-2-B Save the Students(SPOJ AMR11B)解题报告及测试数据
Save the Students Time Limit:134MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descri ...
- Spring-2-A Magic Grid(SPOJ AMR11A)解题报告及测试数据
Magic Grid Time Limit:336MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Tha ...
- Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据
233 Matrix Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descript ...
- Spring-1-H Number Sequence(HDU 5014)解题报告及测试数据
Number Sequence Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Pro ...
- Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice Time Limit:1000MS Memory Limit:65536KB Description There are 2 special dices on the table. ...
随机推荐
- Apache版Phoenix的安装(图文详解)
不多说,直接上干货! 写在前面的话 我这里,三个节点的bigdata集群.分别为master.slave1和slave2. 1.Phoenix的下载 我的HBase版本是hbase-0.98.19. ...
- 【BZOJ1412】[ZJOI2009]狼和羊的故事 最小割
[BZOJ1412][ZJOI2009]狼和羊的故事 Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想: ...
- Vue基础-渲染函数-父子组件-传递数据
Vue 测试版本:Vue.js v2.5.13 做了个 demo,把父子组件的数据都绑定到 Vue 实例 app 上,注释中的 template 相对好理解些 <div id="app ...
- 离线微博工具Open Live Writer(Windows Live Writer)安装过程及server error 500错误解决
必备条件: .net framework 3.5框架(大概是要求3.5或以上,不确定,好像没有人遇到和这个相关的问题) 2017年7月27日最新官方版0.6.2英文离线客户端网盘下载(官网的安装包无法 ...
- iOS中navigationItem修改标题的颜色
UIColor * color = [UIColor redColor];//这里我们设置的是颜色,NSDictionary * dict = [NSDictionary dictionaryWith ...
- Windows上安装zabbix客户端
1.下载解压 https://www.zabbix.com/downloads/3.4.0/zabbix_agents_3.4.0.win.zip conf目录下放有agent配置文件 bin目录下有 ...
- 一个误区(关于javascript的字符串拼接)
前段时间听说了一个问题,说是,javascript中使用+=来拼接字符串会比使用Array的join方法慢几十倍以上,今天在工作间歇,就写了个例 子验证了一下,结果确完全相反,使用+=比join要快( ...
- Appium+python移动端自动化测试-环境搭建(一)
搭建所在系统环境:Windows7版本64位系统 一.环境准备 jdk8.0.151 android-sdk_r20.3.4-windows python3.5 appium1.4.16.1 Node ...
- LayoutInflater的动态增加控件
在实际开发中LayoutInflater这个类是非常有用的,它的作用类似于 findViewById(),不同点是LayoutInflater是用来找layout下xml布局文件. 而findView ...
- Service Receiver Activity 之间的通信
一.Activity与Service 1. 通过Intent,例子如下: Intent intent = new Intent(this, Myservice.class); // intent .p ...