HDOJ 1004 Let the Balloon Rise (字符串+stl)
This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
题意:给出每个气球的颜色 统计出现次数最多的颜色
代码:
#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)的更多相关文章
- 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 ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- 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 ...
- 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 ...
- 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 ...
- 杭电1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 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 ...
- 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 ...
随机推荐
- ARM三级流水线
title: ARM三级流水线 tags: ARM date: 2018-10-14 16:57:10 --- 参考: ARM指令集E004armproc.chm ARM Architecture R ...
- Ubuntu 云服务器上部署自己的 Rails 应用
自学rails一段时间了,之前只用heroku部署了网站,想尝试把网站以一个更“正经”的方式呈现出来,就买了一个阿里云服务器.参考了网上部分rails部署教程,过程中也遇到了一些问题,所以在完成之后总 ...
- ruby 中 手动执行job任务
step1:通过crtk客户端 进入项目主目录 step2:rails c step3:job类名.new.方法名 例:MonthWorkPlanJob.new.perform
- hibernate状态转换关系图【原】
hibernate状态转换 其它参考 简单理解Hibernate三种状态的概念及互相转化 简单的Hibernate入门介绍
- js学习总结:DOM节点二(dom基本操作)
一.DOM继承树 DOM——Document Object Model DOM定义了表示修改文档所需要的方法.DOM对象即为宿主对象,由浏览器厂商定义,用来操作html和xml的一类厂商定义,也有人称 ...
- HTML第二耍 列表标签
先复习下上一节 <!doctype html> <html> <head> <meta charset="utf-8"> <t ...
- [Android] Android 使用 Greendao 操作 db sqlite(2)-- 封装DaoUtils类
继续接上文: Android 使用 Greendao 操作 db sqlite(1)-- 直接在MainActivity中调用 布局文件同上文一致,这里就不贴了. 一.封装DaoUtils类 User ...
- VS WebDev.WebServer40
vs2010下有一个WebDev.WebServer40工具,可以直接拿来当服务器用,这样就不用再安装iis了.位置在 C:\Program Files (x86)\Common Files\micr ...
- SQL 编程技巧
Ø 简介 本文主要介绍编写 SQL 时的一些编程技巧,方便有时候忘了便于查看,主要包含以下内容: 1. SQL 语句中使用 +=.-=.*=./= 运算符 2. 值为 NULL 的列或局部变 ...
- ubuntu安装matplotlib一些坑
ubuntu16.04,python2.7 安装matplotlib, 1.在root权限下执行命令 pip install matplotlib==1.5.1 这里有个困扰我一个星期的问题,系统都被 ...