码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2403

时间:2016-07-24 14:54:30      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

http://poj.org/problem?id=2403

题意:就是给你m个单词,以及n段对话。每一个单词都有所对应的价值。求对话中的价值总和

题解:很简单,就是用单词和价值对应起来,然后再寻找就可以了。

我用的是STL里的map,不用Map的话,结构体也行。只是用Map比较方便而已、

 1 #include <string.h>
 2 #include <string>
 3 #include <map>
 4 #include <iostream>
 5 #include <stdio.h>
 6 
 7 
 8 using namespace std;
 9 
10 map<string,int>s;
11 
12 int m,n;
13 
14 int main()
15 {
16     string tmp;int num;
17     scanf("%d%d",&m,&n);
18     for(int i=0;i<m;i++){
19             cin>>tmp>>num;
20             s[tmp]=num;
21     }
22     for(int i=0;i<n;i++){
23            int ans=0;
24         while(cin>>tmp,tmp!="."){
25             if(s.count(tmp))      //这个count是看tmp是否存在这个map中
26                 ans+=s[tmp];
27         }
28         printf("%d\n",ans);
29     }
30     return 0;
31 }

 

poj 2403

标签:

原文地址:http://www.cnblogs.com/Tree-dream/p/5700701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!