首页 > 其他 > 详细

poj 2503 Babelfish(Map、Hash、字典树)

时间:2015-01-30 15:23:56      阅读:245      评论:0      收藏:0      [点我收藏+]

题目链接:http://poj.org/bbs?problem_id=2503

思路分析:

题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找。

 

代码(Map实现):

#include <iostream>
#include <sstream>
#include <string>
#include <map>
using namespace std;

int main()
{
    char word[15], foreignWord[15], strStream[25];
    map<string, string> dictionary;

    while (gets(strStream) && strStream[0] != \0)
    {
        sscanf(strStream, "%s%s", word, foreignWord);
        dictionary[foreignWord] = word;
    }

    while (cin >> foreignWord)
    {
        if (dictionary.find(foreignWord) != dictionary.end( ))
            cout << dictionary[foreignWord] << endl;
        else
            cout << "eh" << endl;
    }

    return 0;
}

 

poj 2503 Babelfish(Map、Hash、字典树)

原文:http://www.cnblogs.com/tallisHe/p/4262139.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!