@toc
问题描述
格式输入
n
str
str
m
格式输出
排名
样例输入
3
memory
kfc
wind
2
49 memory
49 kfc
48 wind
80 kfc
85 wind
83 memory
样例输出
1
2
评测用例规模与约定
0<n<=10000
str<31
1<=m<=50
解析
用map记录然后解决问题
参考程序
#include<iostream>
#include<map>
using namespace std;
int main()
{
int n,m,p;
map<string,int>shop;
while(cin>>n){
string s;
for(int i=1;i<=n;i++) cin>>s;
cin>>m;
while(m--){
for(int i=1;i<=n;i++){
cin>>p>>s
shop[s]+=p;
}
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;
}
shop.clear();
}
return 0;
}
以个人刷题整理为目的,如若侵权,请联系删除~