andmej / acm

My solutions for problems from the UVa Online Judge (Valladolid).

This URL has Read+Write access

acm / 10295 - Hay Points / 10295.cpp
100644 30 lines (26 sloc) 0.546 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <map>
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  int words, jobs;
  map<string, unsigned long long> dict;
  string s;
  unsigned long long d;
  cin >> words >> jobs;
  for (int i=0; i<words; ++i){
    cin >> s >> d;
    dict[s] = d;
  }
 
  while (jobs--){
    unsigned long long total = 0;
    while (cin >> s && s != "."){
      map<string, unsigned long long>::iterator i = dict.find(s);
      if (i != dict.end()){
        total += i->second;
      }
    }
    cout << total << endl;
  }
  return 0;
}