POJ 2403 Hay Points(水~)

原创 2015年08月27日 09:44:04

Description
首先给出一字典,字典上每个单词有一个对应的键值,然后给出一段信息,让你输出这段信息的总键值,字典上没有出现过的单词键值为0
Input
第一行两个整数m和n,分别表示字典中单词个数和查询信息的条数,之后m行每行一个字符串和一个整数表示单词和其键值,然后是两段信息,每段信息以‘.’结束输入
Output
对于每段信息,输出其键值
Sample Input
7 2
administer 100000
spending 200000
manage 50000
responsibility 25000
expertise 100
skill 50
money 75000
the incumbent will administer the spending of kindergarden milk money
and exercise responsibility for making change he or she will share
responsibility for the task of managing the money with the assistant
whose skill and expertise shall ensure the successful spending exercise
.
this individual must have the skill to perform a heart transplant and
expertise in rocket science
.
Sample Output
700150
150
Solution
简单的字符串匹配
Code

#include <iostream>
#include <string>
using namespace std;
struct word
{
    int date;//键值 
    string a;//单词 
}w[10000];
int main()
{
    int m,n,i;
    cin>>m>>n;
    for (i=0;i<m;i++)
        cin>>w[i].a>>w[i].date;
    while(n--)
    {
        string ch,c;
        int sum=0;
        c=".";//信息输入结束条件        
        while(cin>>ch&&ch!=c)
        {
            for(i=0;i<m;i++)
                if(ch==w[i].a) 
                    sum+=w[i].date;
        }
        cout<<sum<<endl;
    }
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

poj 2403 Hay Points

Hay Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6300   Acc...

TOJ 1391.Hay Points

题目链接:http://acm.tju.edu.cn/toj/showp1391.html 1391.   Hay Points Time Limit: 1.0 Seconds   Memor...

poj2403

Hay Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4964   Accepted: 3215 ...

poj-2403-cup

题目描述 The WHU ACM Team has a big cup, with which every member drinks water. Now, we know the vol...

zoj 2403 || poj 2194 || poj 2850 Stacking Cylinders

买一赠二啊。。。。T T 。。。poj这两题居然完全一样,就输入方式不一样,情何以堪!什么质量啊。。给你最后一排球的坐标,求最顶层的球的坐标。我直接一排一排模拟的,无奈用的三角函数,精度死活达不到,W...

POJ - 2395 Out of Hay(prim)

Out of Hay The cows have run out of hay, a horrible event that must be remedied immediately. Bessi...

POJ 2395 - Out of Hay(最小生成树)

题目: http://poj.org/problem?id=2395 思路: 最小生成数,WA了几遍之后去看discuss发现有重边, prim和kruskal两种算法都写了,当模板咯=.= kusk...

POJ 2305 Out of Hay(Kruscal)

Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14555 Accepted: ...

POJ 2395 Out of Hay (Kruscal最小生成树)

Out of Hay Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15355   Accepted: 5996...

Out of Hay POJ - 2395

大致题意:就是农场的牛跑了,现在牧人要去抓牛,但是从目前到牛的地方有很多条路,现在让你走最短路径,就是最小生成树,然后取最小生成树里面的最大边 大致思路:我用的prim算法,其实就是prim...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:POJ 2403 Hay Points(水~)
举报原因:
原因补充:

(最多只允许输入30个字)