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/ ... 
随机推荐
- Winform中使用Reactivex代替BeginInvoke/Invoke来更新UI数据
			首先通过Nuget安装包System.Reactive. ReactiveX项目 Url: https://github.com/Reactive-Extensions/Rx.NET public p ... 
- ASP.NET + MVC5 入门完整教程五 --- Razor (模型与布局)
			https://blog.csdn.net/qq_21419015/article/details/80451895 1.准备示例项目 为了演示Razor,使用VS创建一个名称为“Razor”的新项目 ... 
- MySQL学习(七) 索引选择(半原创)
			概述 该篇文章主要阐述一个例子(例子来自参考资料,侵删),然后总结今天相关的知识点. 例子 (例子来自参考文章,非原创) 创建表并插入数据,并执行查询 CREATE TABLE `t` ( `id` ... 
- 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线
			959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ... 
- Ubuntu安装程序报错:无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
			问题描述:在使用Ubuntu系统时安装程序时出现下面的报错. E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)E: Unable to ... 
- 第十九篇 vim编辑器的使用技巧
			vim编辑器 ~/.viminfo文件中存储了vim编辑器中常用的命令 vim编辑器共有3中模式:命令模式.末行模式和输入模式,三种模式的转换方式如下图所示: vim 文件名 # 编辑一个文 ... 
- 了解 go 的 Context
			go 的 Context 一直对 go 的 Context 一知半解,不了解其用途,因此在这里着重了解一下 go 语言的 Context 飞雪无情的一个博文对 go 的 Context 讲的比较易懂一 ... 
- Bugku-CTF之PHP_encrypt_1(ISCCCTF)  [fR4aHWwuFCYYVydFRxMqHhhCKBseH1dbFygrRxIWJ1UYFhotFjA=]
			Day34 PHP_encrypt_1(ISCCCTF) fR4aHWwuFCYYVydFRxMqHhhCKBseH1dbFygrRxIWJ1UYFhotFjA= 下载下来.zip文件 
- 类欧几里得模板 p5170
			//类欧几里得的模板题 p5170 //求这三个式子: //第一个跟后两个没关联 //后两个跟其余两个都有关联: #include<cstdio> #include<algorith ... 
- Linux下调试caffe
			参考博客:https://blog.csdn.net/xiaoyezi_1834/article/details/50724875 使用Anjuta 我使用的是ubuntu18.04,安装命令: su ... 
