We all know that FatMouse doesn't speak English. But now he has to be prepared since our nation will join WTO soon. Thanks to Turing we have computers to help him.
Input Specification
Input consists of up to 100,005 dictionary entries, followed by a blank line, followed by a message of up to 100,005 words. Each dictionary entry is a line containing an English word, followed by a space and a FatMouse word. No FatMouse word appears more than once in the dictionary. The message is a sequence of words in the language of FatMouse, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output Specification
Output is the message translated to English, one word per line. FatMouse 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
Output for Sample Input
cat eh loops
AC代码:
#include<iostream>
#include<map>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
map<string,string> word;
map<string,string>::iterator i;
char s[25],s1[15],s2[15];
while(gets(s)){
if(strcmp(s,"")==0)
break;
sscanf(s,"%s %s",s1,s2);
word[s2]=s1;
}
while(cin>>s){
if((i=word.find(s))!=word.end())
cout<<i->second<<endl;
else
cout<<"eh"<<endl;
}
return 0;
}
本文介绍了一个简单的程序,用于将一种虚构的语言FatMouse语言翻译成英语。该程序使用字典映射来完成翻译任务,对于未出现在字典中的词汇,则默认翻译为eh。示例输入展示了如何构造字典及翻译过程。
1442

被折叠的 条评论
为什么被折叠?



