map的应用。开始以为只有一组数据。其实不是。。
本来是想用这道题来练习hash的。不过这题的hash貌似还有点复杂。就直接用map模拟了。。
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string,int> shop;
int main()
{
int n,m,p;
while(cin>>n)
{
string s;
for(int i=1;i<=n;i++)
{
cin>>s;
shop[s]=0;
}
cin>>m;
while(m--)
{
for(int i=1;i<=n;i++)
{
cin>>p>>s;
shop[s]+=p;
}
int flag=shop["memory"];
int rank=1;
map<string,int>::iterator it;
for(it=shop.begin();it!=shop.end();it++)
{
if((*it).second>flag)
rank++;
}
cout<<rank<<endl;
}
shop.clear();
}
return 0;
}
本文介绍了一道HDU在线编程竞赛题目,并通过使用C++中的map数据结构进行解决。文章详细展示了如何读取并处理输入数据,以及如何利用map记录各商店得分,并最终输出排名。
2万+

被折叠的 条评论
为什么被折叠?



