Poj 2503 Babelfish

来源:互联网 发布:老司机 知乎 收藏夹 编辑:程序博客网 时间:2024/06/05 18:24
Babelfish
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 34221 Accepted: 14678

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Sample Output

catehloops

Hint

Huge input and output,scanf and printf are recommended.


题意:

输入一个字典,字典格式为“英语à外语”的一一映射关系

然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh”


偷个懒,直接用map水了;


#include <iostream>#include <string>#include <map>#include <set>using namespace std;int main(){    string s, a, b;    map<string, bool> apperance;    map<string, string>dic;    while (getline(cin, s) && s != ""){        int pos = s.find(' ');        a.assign(s, 0, pos);        b.assign(s, pos+1, s.size()-1);        apperance.insert(make_pair(b, true));        dic.insert(make_pair(b, a));    }    while (cin >> s){        if (apperance[s]){            cout << dic[s] << endl;        }        else{            cout << "eh" << endl;        }    }}


0 0
原创粉丝点击