Babelfish

来源:互联网 发布:音乐版权 知乎 编辑:程序博客网 时间:2024/06/05 10:03

/*Babelfish
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 ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay
Sample Output
cat
eh
loops*/
//题意:给出一些english和foreign对应的词典,然后是一行空格,接着是一些foreign,要求判断这些
//foreign是否在词典中,若在则输出其对应的english,不在则输出‘eh’

#include<stdio.h>#include<iostream>using namespace std;#include<string>#include<map>int main(){       char english[15],foreign[15];    map<string,bool>s;    map<string,string>c;    while(true)    {        char t;        if((t=getchar())=='\n')            break;        else        {            english[0]=t;            int i=1;            while(true)            {                t=getchar();                if(t==' ')                {                    english[i]='\0';                    break;                }                else                    english[i++]=t;            }        }        scanf("%s",foreign);        getchar();        s[foreign]=true;        c[foreign]=english;    }    char a[15];    while(~scanf("%s",a))    {        if(s[a])        {            //printf("%s\n",c[a]);            cout<<c[a]<<endl;        }        else           //printf("eh\n");            cout<<"eh"<<endl;    }    return 0;}
0 0
原创粉丝点击