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

时间:2023-03-08 17:24:11

题目链接: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[], foreignWord[], strStream[];
map<string, string> dictionary; while (gets(strStream) && strStream[] != '\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 ;
}