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 ...
随机推荐
- java开发常用的日期格式转换工具类
package com.ydtf.ipcc.sms.util; import java.sql.Timestamp; import java.text.SimpleDateFormat; import ...
- vue init 解决办法
/由于windows系统的某方面问题,vue脚手架安装可能会出现第一证书丢失 // 报错:vue-cli · Failed to download repo vuejs-templates/webpa ...
- MySQL_参数设置
1.max_allowed_packet 描述:有时备份数据库时,将本地psc文件备份到数据库时,会遇见备份不成功的情况 分析:这时要考虑,是否由于max_allowed_packet这个参数过小,导 ...
- MyBatis-Helloworld
一.依赖配置 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...
- 13.模板方法(Template Method)
无处不在的Template Method 如果你只想掌握一种设计模式,那么它就是Template Method!动机(Motivate): 变化 -----是软件设计的永恒主题,如何管理 ...
- vs code配置git
在项目目录执行 git init 修改.git文件夹下的config文件 [core] repositoryformatversion = 0 filemode = false bare = fals ...
- [leetcode-128] 最长连续序列
给定一个未排序的整数数组,找出最长连续序列的长度. 要求算法的时间复杂度为 O(n). 示例: 输入: [100, 4, 200, 1, 3, 2] 输出: 4 解释: 最长连续序列是 [1, 2, ...
- Java中的AES加解密
直接上代码,Base64使用的是Java8的方法,如没有,替换即可 KEY:即密码 IV:即偏移量,可自订,十六位 加密方式:AES/CBC/PKCS5Padding,128位加密 如果想用256位和 ...
- docker 系列 - Docker CheatSheet | Docker 配置与实践清单 (转载)
本文转载自 (https://segmentfault.com/a/1190000016447161), 感谢作者.
- SpringBoot系列: 理解 Spring 的依赖注入(二)
==============================Spring 容器中 Bean 的名称==============================声明 bean 有两个方式, 一个是 @B ...