yipo
12/6/2015 - 7:36 AM

Newspaper

Newspaper

#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

vector<int> read_table() {
	int k;
	cin>>k;

	vector<int> table(256,0);
	while (k--) {
		unsigned char ch;
		cin>>ch;
		cin>>table[ch];
	}
	return table;
}

int eval_article(const vector<int> &table) {
	int m;
	cin>>m;
	cin.ignore(1,'\n');

	int sum=0;
	while (m--) {
		string line;
		getline(cin,line);
		for (unsigned char ch:line) sum+=table[ch];
	}
	return sum;
}

void test_case() {
	const vector<int> table=read_table();
	const int value=eval_article(table);
	cout<<(value/100)<<'.'<<setw(2)<<setfill('0')<<(value%100)<<'$'<<endl;
}

int main() {
	int n;
	cin>>n;
	while (n--) test_case();
	return 0;
}