题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=2403
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
#include
<
map
>
#include < iostream >
#include < string >
#include < vector >
using namespace std;
int main()
{
int m,n;
map < string , int > dict;
cin >> m >> n;
int i;
string word;
int nValue;
for (i = 0 ;i < m; ++ i)
{
cin >> word >> nValue;
dict[word] = nValue;
}
for (i = 0 ;i < n; ++ i)
{
int sum = 0 ;
while (cin >> word && word != " . " )
{
if (dict.find(word) != dict.end())
{
sum += dict[word];
}
}
cout << sum << endl;
}
return 0 ;
}
#include < iostream >
#include < string >
#include < vector >
using namespace std;
int main()
{
int m,n;
map < string , int > dict;
cin >> m >> n;
int i;
string word;
int nValue;
for (i = 0 ;i < m; ++ i)
{
cin >> word >> nValue;
dict[word] = nValue;
}
for (i = 0 ;i < n; ++ i)
{
int sum = 0 ;
while (cin >> word && word != " . " )
{
if (dict.find(word) != dict.end())
{
sum += dict[word];
}
}
cout << sum << endl;
}
return 0 ;
}