Ant is a student in Tianjin University. Everyday, he has to go to the restaurant in school. Recently, some other students complain about the high price of restaurant dishes. Ant is a poor man, he don't want to spend too much. Then he wants to know the total price of the dishes he wants to order before he pays for them. Now he wants to write a program to help him calculate the price. Could you help him?
Input
There are several test case in the input file. For each test case, the first line contains two integer n and m, seperated by a single space. n is the number of all the dishes and m is the number of the dishes that Ant wants to order. Then n ( 0 < n ≤ 100) lines follows and each line contains one string si and an real number ai. The string si is the name of the i-th dish and the real number ai is the price of the i-th dish. The length of string si is less than 10. The next m following lines describe the dishes which Ant wants to order and each of them contains a string which is the name of dish. Every dish is calculated only once.
Output
For each test case, output a real number which is the total price in a line. The total price should be printed with two digits to the right of the decimal point.
Sample Input
3 2 rice 0.5 egg 2.0 meat 5.0 meat rice
Sample Output
5.50
#include<map>
#include<iomanip>
using namespace std;
int main()
{
int n,m;
double price,sum=0;
string name;
map<string,double>Set;
while(cin>>n>>m)
{
for(int i=0;i<n;++i)
{
cin>>name>>price;
Set[name]=price;
}
for(int i=0;i<m;++i)
{
cin>>name;
sum+=Set[name];
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<sum<<endl;//按固定格式输出
Set.clear();
sum=0;
}
return 0;
}