summaryrefslogtreecommitdiff
path: root/11340/newspaper.cpp
blob: 50f8d85f45e3548b2707687a2f2d6fb71665ca62 (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
31
32
33
34
#include <iostream>
#include <string>
#include <cstdio>
#include <limits>
using namespace std;

int main(){
    int tc;
    cin>>tc;
    for(int i=0; i<tc; i++){
	int k, costmap[256]={0}, lines, cost;
	double totcost=0;
	unsigned char c;
	string line;
	cin>>k;
	for(int j=0; j<k; j++){
	    scanf("%hhu", &c);
	    scanf("%i", &cost);
	    costmap[c] = cost;
	}
	
	lines=cin.get();
	cin.ignore();
	for(int j=0; j<lines; j++){
	    getline(cin, line);
	    for(int l=0; line[l]!='\n' && line[l]!='\r'; l++){
		totcost += costmap[line[l]];
	    }
	}
	cout.precision(2);
	cout<<fixed<<totcost/100<<"$\n";
    }
    return 0;
}