POJ 2503 Babelfish

来源:互联网 发布:gis空间分析实例数据 编辑:程序博客网 时间:2024/06/05 15:23
Babelfish
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 40265 Accepted: 17159

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.


这题的做法有很多,排序加二分,字典树,哈希都可以,最简单粗暴的就是直接用map水。
#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<string>using namespace std;int main(){    map<string,string>A;    char a[110],b[110],c[110];    while(gets(a)&&a[0]!='\0')    {        sscanf(a,"%s%s",&b,&c);        A[c]=b;    }    while(~scanf("%s",&a))    {        if(A.find(a)==A.end()) cout<<"eh"<<endl;        else cout<<A[a]<<endl;    }    return 0;}




0 0
原创粉丝点击