#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int i,j,k,l,m,n,sum,f;
string sk,s;
char sen[100000],c;
map<string,int>a;
map<string,int>::iterator it=a.begin();
vector<string>st;
vector<string>::iterator jt=st.begin();
//freopen("10295.txt","r",stdin);
//freopen("10295out.txt","w",stdout);
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>sk>>k;
a.insert(make_pair(sk,k));
}
for(l=1;l<=m;l++)
{
if(l==1)
{
cin.ignore();
}
st.clear();
sum=0;
while(gets(sen))
{
if(sen[0]=='.')
{
break;
}
for(i=0;i<strlen(sen);i++)
{
s="";
while(1)
{
if(isupper(sen[i]))
{
sen[i]=tolower(sen[i]);
}
if(sen[i]=='.')
{
goto level;
}
if(sen[i]==' ')
{
break;
}
else if(sen[i]>='a' && sen[i]<='z')
{
s=s+sen[i];
}
else
{
break;
}
i++;
}
st.push_back(s);
}
}
level:
for(jt=st.begin();jt!=st.end();jt++)
{
for(it=a.begin();it!=a.end();it++)
{
if(*jt==it->first)
{
sum=sum+it->second;
}
}
}
cout<<sum<<endl;
}
return 0;
}
0 comments:
Post a Comment