include iostream include map using namespace std int main int wordcoun

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <map>
using namespace std;
int main()
{
int wordcount, texts;
cin >> wordcount >> texts;
map<string,int> words;
while(wordcount--)
{
string word;
int val;
cin >> word >> val;
words[word]=val;
}
/*
map<string,int>::iterator word;
for(word=words.begin();word!=words.end();word++)
{
cout << (*word).first << " => " <<(*word).second << endl;
}*/
while (texts--)
{
int res=0;
string line;
while(getline(cin,line) && line!=".")
{
map<string,int>::iterator word;
for(word=words.begin();word!=words.end();word++)
{
int lastpos = 0;
while ((lastpos=line.find((*word).first, lastpos))!=string::npos)
{
res+=(*word).second;
lastpos+=(*word).first.length();
}
}
}
cout << res << endl;
}
}