题目链接: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; }
时间: 2024-10-12 01:10:13