#UVa:10295-Hay Points

將單字建成表後,遇到文章就將每個字查表總和即是解答。

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;
}
廣告

Comment

There is no comment on this post. Be the first one.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

%d 位部落客按了讚: