Click Here to go back to the homepage.

Hay Points Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int dictionarySize, people;
    cin >> dictionarySize >> people;
    map<string, int> dictionary;
    while(dictionarySize--){
        string word;
        int value;
        cin >> word >> value;        
        dictionary.insert({word, value});
    }
    while(people--){
        int sum = 0;
        string word = "";
        while(word != "."){
            cin >> word;
            auto it = dictionary.find(word);
            if(it != dictionary.end()){
                sum += it->second;
            }
        }
        cout << sum << endl;
    }


    return 0;   
}