#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<cstring>
#define db(a) cout << #a << " = " << a << endl;
#define db2(a, b) cout << #a << " = " << a << " -- "<< #b << " = " << b << endl;
#define foreach(it, l) for(typeof(l.begin()) it = l.begin(); it != l.end(); it++)
using namespace std;
int main(){
map mapa;
int t = 0, keys, lines, valor;
double pagar = 0.;
string linea;
char test[10], clave;
bool first;
cin.getline(test, 10, '\n');
t = atoi(test);
for(int i = 0; i < t; i++){
mapa.clear();
pagar =0.;
cin.getline(test, 10, '\n');
keys = atoi(test);
for(int k = 0; k < keys; k++){
getline(cin, linea);
char *st, *buf, sep[] = " ";
buf = strdup(linea.c_str());
st = strtok(buf, sep);
first = true;
valor = 0;
while(st){
if(first){
clave = st[0];
first = false;
}
else{
valor = atoi(st);
}
st = strtok(0, sep);
}
mapa[clave] = valor;
}
cin.getline(test, 10, '\n');
lines = atoi(test);
//db(lines);
for(int l = 0; l < lines; l++){
getline(cin, linea);
int len = linea.size();
for(int v = 0; v < len; v++){
if(mapa[linea[v]]) pagar += mapa[linea[v]] * 0.01;
}
}
printf("%.2f$\n", pagar);
}
/*foreach(it, mapa){
db2(it->first, it->second);
}*/
return 0;
}
lunes, 24 de octubre de 2011
11340 - Newspaper, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario