POJ 2403

 1 #include <iostream>
 2 #include <map>
 3 #include <string>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 map<string,int> coll;
 8 
 9 int main()
10 {
11     //freopen("acm.acm","r",stdin);
12     int num;
13     int test;
14     int i;
15     string s;
16     int cost;
17     cin>>num;
18     cin>>test;
19     map<string,int>::iterator pos;
20     for(i = 0; i < num; ++ i)
21     {
22         cin>>s>>cost;
23         //coll[s] = cost;
24         coll.insert(pair<string,int>(s,cost));
25     }
26     int sum;
27     for(i = 0; i < test; ++ i)
28     {
29         sum = 0;
30         while(cin>>s)
31         {
32         //    cout<<sum<<endl;
33             if(s == ".")
34                 break;
35             else 
36             {    
37                 pos = coll.find(s);
38                 if(pos != coll.end())
39                 {
40                     sum += pos->second;
41                 //    cout<<"___________"<<pos->second<<endl;
42                 }
43             }
44         }
45         //coll.clear();
46         cout<<sum<<endl;
47 
48     }
49 }
原文地址:https://www.cnblogs.com/gavinsp/p/4568420.html