hdu2648 STL map的简单应用

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2648

代码如下:

 1 #include<iostream>
 2 #include<map>
 3 using namespace std;
 4 map<string,int> mp;
 5 string s;
 6 int n,m;
 7 int main()
 8 {
 9     while(cin>>n)
10     {
11         mp.clear();
12         int p;
13         for(int i=0;i<n;i++)
14         {
15             cin>>s;
16             mp[s]=0; 
17         }
18         cin>>m;
19         while(m--)
20         {
21             for(int i=0;i<n;i++)
22             {
23                 cin>>p>>s;
24                 mp[s]+=p;
25             }
26             map<string,int>::iterator it;
27             int rank=1;
28             for(it=mp.begin();it!=mp.end();it++)
29             {
30                 if(it->second>mp["memory"])rank++;
31             }
32             cout<<rank<<endl;
33         }
34     }
35 } 
原文地址:https://www.cnblogs.com/randy-lo/p/12609770.html