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/ ...
随机推荐
- 剑指offer(leetcode 10.) 正则表达式匹配
这题一年前就做过,当时刚开始刷leetcode,提交了几十次过不去,就放那没管了.今天剑指offer又遇到这题,终于做出来了,用的dp. class Solution { public: bool i ...
- android toolbar 显示返回按钮并改变按钮颜色
<android.support.design.widget.AppBarLayout android:id="@+id/about_appbar" android:layo ...
- IntelliJ IDEA 2017.3尚硅谷-----版本控制(Version Control)
不管是个人开发还是团队开发,版本控制都会被使用.而 IDEA 也很好的集成了 版本控制的相关结构. Git 的 msysGit 官网下载:https://git-scm.com/ Git 客户端 To ...
- 什么是类的hashcode值
1.要知道什么是类的hashcode值,首要要了解什么是hash(哈希).Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射pre-image)通过散列算法变换 ...
- python之路之线程,进程,协程2
一.线程 1.创建线程 2.主线程是否等待子线程 t.setDaemon(Ture/False):默认是false,等待子线程完成,ture,表示不等待子线程结束 3.主线程等待,子线程执行 join ...
- laravel环境安装
参考 https://blog.csdn.net/xiaomayi721025/article/details/84727405 环境准备
- MVC5+EF6 入门完整教程4 :EF基本的CRUD
上篇文章主要讲了如何配置EF, 我们回顾下主要过程: 创建Data Model ---> 创建Database Context --->创建databaseInitializer---&g ...
- python后续学习
关于使用python输出中文字符的问题: Python中默认的编码格式是 ASCII 格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错. 解决方法为只要在文件开头加入 # -*- co ...
- AcWing 154. 滑动窗口
https://www.acwing.com/problem/content/156/ #include <iostream> using namespace std; ; int a[N ...
- HDU4714 Tree2cycle 解题报告
题意 给定一棵无根树,删除或连接一条边的代价为\(1\),求把树变为环的最小代价. 前置思路 如果删除了\(k\)条边,使得树变成\((k+1)\)条链,再用\((k+1)\)次连接操作把树变成一个环 ...