题目:
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

题意:给出每个气球的颜色 统计出现次数最多的颜色
思路:网上的代码大多数都是开两个数组来记录 自己的方法是用stl中的map函数来做 用map计数然后排序 但是map并不是线性的 不能用sort 需要转换

代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n;
string s; void value(vector<pair<int,string>> & vec,map<string,int> & mp){
for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
vec.push_back(make_pair(it->second,it->first));
}
sort(vec.begin(),vec.end());
} int main(){
while(~scanf("%d",&n)){
if(n==) break;
vector<pair<int,string>> vec;
map<string,int>mp;
while(n--){
cin>>s;
mp[s]++;
}
value(vec,mp);
vector<pair<int,string>>::iterator it=vec.end()-;
cout<<it->second.c_str()<<endl;
}
return ;
}

题外话:关于排序

  sort算法只能对线性的容器进行排序 例如vector list deque 但是map是一个集合容器 里面存储的元素是pair 内部是按序存储的 比如红黑树 如此就不能用sort进行排序 为了解决这个问题 可以把map中的元素放入到vector 从而进行排序操作

 
 

HDOJ 1004 Let the Balloon Rise (字符串+stl)的更多相关文章

  1. 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 ...

  2. HDOJ 1004 Let the Balloon Rise

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

  3. HDU 1004 Let the Balloon Rise(STL初体验之map)

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

  4. 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 ...

  5. 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 ...

  6. 杭电1004 Let the Balloon Rise

    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

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

  8. 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 ...

  9. 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 ...

随机推荐

  1. 运维监控-使用Zabbix Server 创建触发器Triggers

    运维监控-使用Zabbix Server 创建触发器Triggers  作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1>.点击相应主机的触发器 2>.点击创建触发器 ...

  2. Elastic Stack之ElasticSearch分布式集群二进制方式部署

    Elastic Stack之ElasticSearch分布式集群二进制方式部署 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 想必大家都知道ELK其实就是Elasticsearc ...

  3. dubbo基础

    一.什么是dubbo,有什么用 dubbo是阿里巴巴开源的一个RPC框架,用于多个应用相互通信.使用dubbo需要安装一zookepper 二.dubbo的基本使用 1.构建一个maven的多模块项目 ...

  4. Java动态代理之JDK实现和CGlib实现(简单易懂)

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6542259.html 一:代理模式(静态代理) 代理模式是常用设计模式的一种,我们在软件设计时常用的代理一般是 ...

  5. MVC项目报错 ”基础提供程序在 Open 上失败”

    问题: 今天将一个.net mvc项目拷贝到另一台电脑上,重新部署的时候,出现以下异常信息: “System.Data.Entity.Core.EntityCommandExecutionExcept ...

  6. ruby-----render讲解

    Ruby rails页面跳转代码如下: 1.render(:text => string) 2.render(:inline => string, [:type => "r ...

  7. shop++改造之Filter类

    基于shop++源码进行商城改造.本来想大展手脚,结果一入手.发觉瞬间淹没了我的才华,sql语句也得贼溜没啥用. 不得不说这个商城源码价值很高,封装的很精屁. 下面是我第一天入手的坑. 数据库建好了表 ...

  8. redis基本操作

    ''' pip install redis redis 可以看成内存中的大字典 redis五大数据类型 --> 指的是第一层的value值的类型 - 字符串 "k1" - 列 ...

  9. Photoshop影像匀色技术

    本篇博文简单介绍一下利用PhotoShop对影像数据进行匀色的相关技术 影像一般有img和tif两种各种.一般的影像如果在PS中打开,会丢失坐标信息.在做匀色处理中,普通的做法是,先将坐标信息导出来, ...

  10. jquery 控制 video 视频播放和暂停

    $('video').trigger('play'); $('video').trigger('pause'); 参考:https://blog.csdn.net/arvin0/article/det ...