map的使用-Hdu 2648
Shopping
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6348 Accepted Submission(s): 2215
Then n lines ,each line contains a string (the length is short than 31 and only contains lowercase letters and capital letters.)stands for the name of the shop.
Then a line contians a number m (1<=m<=50),stands for the days .
Then m parts , every parts contians n lines , each line contians a number s and a string p ,stands for this day ,the shop p 's price has increased s.
int rank = ;
map<string,int>::iterator it;
for(it = shop.begin();it != shop.end(); it++){
if(it->second>shop["memory"])
rank++;
}
cout<<rank<<endl;
所以我经过查阅资料发现了另一种方法,用一个数组来把价格存起来,然后用sort排序后,再通过比较数组中的值是否和“memory”商店的价格相等来输出他的位置,即为他的排名
#include <iostream>
#include <string>
#include <map>
#include <algorithm> using namespace std; bool my_camp(int x,int y){
return x>y;
} int main()
{
int n,m,p;
int a[];
map<string,int>shop;
while(cin>>n){
string s;
for(int i = ;i <= n; i++)
cin>>s;
cin>>m;
while(m--){
for(int i = ;i <= n; i++){
cin>>p>>s;
shop[s] += p;
a[i] = shop[s];
}
/*int rank = 1;
map<string,int>::iterator it;
for(it = shop.begin();it != shop.end(); it++){
if(it->second>shop["memory"])
rank++;
}
cout<<rank<<endl; */
sort(a+,a+n+,my_camp);
for(int i = ;i <= n; i++){
if(a[i] == shop["memory"]){
cout<<i<<endl;
break;
}
}
}
shop.clear();
}
return ;
}
map的使用-Hdu 2648的更多相关文章
- hdu 2648 Shopping
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2648 纯暴力的方法T_T... 如下: #include<cstdio> #include ...
- STL复习之 map & vector --- disney HDU 2142
题目链接: https://vjudge.net/problem/40913/origin 大致题意: 这是一道纯模拟题,不多说了. 思路: map模拟,vector辅助 其中用了map的函数: er ...
- HDU 2648(搜索题,哈希表)
#include<iostream> #include<map> #include<string> #include<cstring> #include ...
- 第一周训练 | STL和基本数据结构
A - 圆桌问题: HDU - 4841 #include<iostream> #include<vector> #include<stdio.h> #includ ...
- stl_map,set 用法
set: 集合a,b加起来,去重 hdu 1406 #include <iostream> #include<cstdio> #include<set> using ...
- Hash算法入门指南(聊点不一样的算法人生)
前言 很多人到现在为止都总是问我算法该怎么学啊,数据结构好难啊怎么的,学习难度被莫名的夸大了,其实不然.对于一个学计算机相关专业的人都知道,数据结构是大学的一门必修课,数据结构与算法是基础,却常常容易 ...
- HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...
- hdu 1075 (map)
http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...
- hdu 1800 (map)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...
随机推荐
- c数据结构 -- 线性表之 复杂的链式存储结构
复杂的链式存储结构 循环链表 定义:是一种头尾相接的链表(即表中最后一个结点的指针域指向头结点,整个链表形成一个环) 优点:从表中任一节点出发均可找到表中其他结点 注意:涉及遍历操作时,终止条件是判断 ...
- laravel如何A表中包含B表中信息
A表中如何包含B表中的信息 首先看A表的信息 接着看B表的信息 我的需求就是 A表字段name对应B表字段ream_name然后得到B表的对应主键ID要在A表中查询出来 发现问题就是查询出来的id和A ...
- MySQL学习(八)删除表数据
表空洞的产生 删除某个行数据 或删除某个页 如下图所示,这个删除过程只是标记了某行的位置为删除,假如此时在300与600之间插入了一行数据,那么 同理,当删除某个页时,该页就会被复用.所以当删 ...
- .net core 2.2 使用imagemagick 将pdf转化为png
工作需要将PDF文件每一页拆分为一个一个的png文件 测试环境:mac,visual studio for mac 2019 nuget:magick.net-Q16-AnyCPU 不能直接支持PDF ...
- LED Magic Light - How Does The LED Light Change Color?
The LED Magic Light states that the color-changing LED is not an LED in the package, but three ...
- (c#)奇数值单元格的数量
题目 解
- 传奇服务端添加双倍经验卷的方法 双倍经验卷轴DB示例展示
第一步我们在DBC数据库中添加好双倍经验卷轴DB,以下是现成的双倍经验卷DB,导入到DB里面就可以了. 222;双倍经验卷;31;0;1;20;0;0;265;0;0;0;0;0;0;0;0;0;0; ...
- 微信小程序 - height: calc(xx - xx);无效
遇到一个小问题,记录一下 问题:在微信小程序中使用scroll-view标签时,用height:cale(xx - xx)设置高度无效,在page中设置高度为百分百依旧无效 解决办法:直接在父级vie ...
- CTF_论剑场 头像
首先打开链接发现这个链接是一个头像 然后下载这个头像 通过hxd分析一下 在编辑中查找 flag 然后发现flag是一个用base64 加密的一串文字 然后我们将这串文字 解密 然后再通过md5 32 ...
- 【 SSH 实例】使用ssh开发的简单项目
简单的员工管理项目,使用spring.struts1.hibernate开发 applicationContext.xml <?xml version="1.0" encod ...