summaryrefslogtreecommitdiff
path: root/11340/newspaper.cpp
blob: f5043cf445ecba7967a8186aba73e8762908fc65 (plain)
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 <iostream>
#include <string>
using namespace std;

int main(){
    int tc;
    cin>>tc;
    while(tc--){
	int k, costmap[500]={0}, lines, cost;
	double totcost=0;
	string line, s;
	cin>>k;
	while(k--){
	    cin>>s>>cost;
	    costmap[int(s[0])+128]=cost;
	}
	
	cin>>lines;
	cin.ignore();
	while(lines--){
	    getline(cin, line);
	    for(int l=0; l<line.length(); l++){
		totcost += costmap[line[l]+128];
	    }
	}
	cout.precision(2);
	cout<<fixed<<totcost/100<<"$\n";
    }
    return 0;
}