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.

 
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

题目大意:如题

思路:创建一个map<string, int>, 通过cnt["string"]=int的方法储存值,学习其中关于“找a是否存在,不存在就先让它为0,再加1,存在就直接加一”

代码如下

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<stdlib.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 1e5 + 100;
double eps = 1e-8;
map<string, int> cnt;
int main(){
int n;
while(scanf("%d", &n) && n){
cnt.clear();
string a;
int ans =0;
string anss;
for(int i = 0; i < n ; i++){
cin >> a;
if(!cnt.count(a))cnt[a]=0;
cnt[a]++;
if(cnt[a]>ans){
ans =cnt[a];
anss = a;
}
}
cout << anss << endl; } return 0;
}

HDU 1004 Let the Balloon Rise(STL初体验之map)的更多相关文章

  1. hdu 1004 Let the Balloon Rise(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  2. HDU 1004 Let the Balloon Rise(map的使用)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  3. HDU 1004 Let the Balloon Rise【STL<map>】

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. hdu 1004 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  5. HDU 1004 Let the Balloon Rise map

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. hdu 1004 Let the Balloon Rise strcmp、map、trie树

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  7. hdu 1004 Let the Balloon Rise 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...

  8. HDU 1004 - Let the Balloon Rise(map 用法样例)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. HDU 1004 Let the Balloon Rise(map应用)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. 我与Git的那些破事--代码管理实践

    1. Git是什么? 作为一名程序猿,我相信大家都或多或少接触过git--分布式版本控制软件. 有人说,它是目前世界上最先进的分布式版本控制系统,我想说,是否最先进不知道,但确实好用,实用. 作为一款 ...

  2. Spark学习笔记(一)——基础概述

    本篇笔记主要说一下Spark到底是个什么东西,了解一下它的基本组成部分,了解一下基本的概念,为之后的学习做铺垫.过于细节的东西并不深究.在实际的操作过程中,才能够更加深刻的理解其内涵. 1.什么是Sp ...

  3. Redis系列之----Redis的两种持久化机制(RDB和AOF)

    Redis的两种持久化机制(RDB和AOF) 什么是持久化    Redis的数据是存储在内存中的,内存中的数据随着服务器的重启或者宕机便会不复存在,在生产环境,服务器宕机更是屡见不鲜,所以,我们希望 ...

  4. C++ string 常用函数

    C++ String常用函数 一,类型别名 size_type 无符号整型 iterator 迭代器类型 const_iterator 只读迭代器 reverse_iterator 逆序迭代器 con ...

  5. DbCommand :执行超时已过期。完成操作之前已超时或服务器未响应。

    问题:“Timeout 时间已到.在操作完成之前超时时间已过或服务器未响应.”的解决方法 在一个链接数据库的时候,老是出现超时的错误:执行超时已过期.完成操作之前已超时或服务器未响应. 就是给这个链接 ...

  6. WingIDE注册破解方法 CalcActivationCode.py

    1) 安装WingIDE成功后启动,激活时输入license id CN123-12345-12345-12345 2) 点击Continue后弹框,拷贝框中的request code 3) 修改Py ...

  7. Nginx代理服务——常用的配置语法

    可以到官方查看所有代理的配置语法http://nginx.org/en/docs/http/ngx_http_proxy_module.html 缓存区 Syntax:proxy_buffering ...

  8. 【5min+】传说中的孪生兄弟? Memory and Span

    系列介绍 [五分钟的dotnet]是一个利用您的碎片化时间来学习和丰富.net知识的博文系列.它所包含了.net体系中可能会涉及到的方方面面,比如C#的小细节,AspnetCore,微服务中的.net ...

  9. 12.instanceof和类型转换

    Instanceof: 判断一个对象是什么类型的~,可以判断两个类之间是否存在父子关系 package com.oop.demo07; public class Person { public voi ...

  10. Linux下安装Ant

    前言 Apache Ant 是一个构建工具,可以将软件编译.测试.部署等步骤联系在一起完成自动化工作,比如可以利用Ant来执行Jmeter的 jmx 脚本,生成了 jtl 测试结果文件,接着再利用An ...