POJ 2503 Babelfish(STL-map)

来源:互联网 发布:彗星dns优化 编辑:程序博客网 时间:2024/06/05 18:11

Babelfish
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 40446 Accepted: 17225

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搞搞,不过G++会TLE,C++能过 (;′⌒`)


代码如下:


#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<map>using namespace std;#define maxn 100010char str[20],s[20],word[20];int main(){map<string,bool>appear;map<string,string>translate;int i;while(1){char t;t=getchar();if(t=='\n')break;else{str[0]=t;i=1;while(1){t=getchar();if(t==' '){str[i]='\0';break;}str[i++]=t;}}scanf("%s",s);getchar();appear[s]=true;translate[s]=str;} while(scanf("%s",word)!=EOF){if(appear[word])cout<<translate[word]<<endl;elseprintf("eh\n");}return 0;} 



0 0
原创粉丝点击