將單字建成表後,遇到文章就將每個字查表總和即是解答。
C++(0.000)
/*******************************************************/
/* UVa 10295 Hay Points */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2018/09/27 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main(){
int m, n;
while(scanf("%d%d", &m, &n) != EOF){
map<string, int> dictionary;
for(int i = 0 ; i < m ; ++i){
char word[20];
int hayPoint;
scanf("%s%d", word, &hayPoint);
dictionary[string(word)] = hayPoint;
}
for(int i = 0 ; i < n ; ++i){
string descriptionWord;
int totalHayPoints = 0;
while(cin >> descriptionWord && descriptionWord != "."){
totalHayPoints += dictionary[descriptionWord];
}
printf("%d\n", totalHayPoints);
}
}
return 0;
}