#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, m, i, tk;
cin >> n >> m;
string s;
map<string, int>mp;
for(i=1;i<=n;i++)
{
cin >> s;
cin >> tk;
mp[s] = tk;
}
for(i=1;i<=m;i++)
{
string w;
long sum = 0;
while(getline(cin, s) && s != ".")
{
stringstream st(s);
while(st >> w)
{
if(mp[w] > 0)
{
sum = sum + mp[w];
}
}
}
cout << sum << "\n";
}
return 0;
}
using namespace std;
int main()
{
int n, m, i, tk;
cin >> n >> m;
string s;
map<string, int>mp;
for(i=1;i<=n;i++)
{
cin >> s;
cin >> tk;
mp[s] = tk;
}
for(i=1;i<=m;i++)
{
string w;
long sum = 0;
while(getline(cin, s) && s != ".")
{
stringstream st(s);
while(st >> w)
{
if(mp[w] > 0)
{
sum = sum + mp[w];
}
}
}
cout << sum << "\n";
}
return 0;
}
Comments
Post a Comment