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
题目大意:
把老鼠的语言翻译成英语输出,翻译不了就输出eh,输入每一行分别是英语和该英语对应的鼠语。
解题思路:
这个题要么哈希一下要么就是直接用STL中的map就可以很轻松的解决。但难点在于输入上,常规的将字符串整个输入的方法难以区别我们的输入格式。本题的输入技巧是首先输入第一个字符串得第一个字符并判断它是否是回车,如果是则map的构建结束,否则继续进行。注意在每一行输入后用getchar()吃掉一个回车。
代码如下:
#include<iostream>
#include<cstdio>
#include<fstream>
#include<set>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<iomanip>
#include<cstdlib>
#include<list>
#include<queue>
#include<stack>
#include<algorithm>
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define meminf(a) memset(a,inf,sizeof(a))
#define HASHP 13331;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
char a[100010],b[100010];
int main()
{
// std::ios::sync_with_stdio(false);
// cin.tie(0);
//freopen("test.txt","r",stdin);
//freopen("output.txt","w",stdout);
map<string,string> ma;
string c,d;
while(scanf("%c",a)&&a[0]!='\n')
{
scanf("%s %s",a+1,b);
getchar();//输入结束的换行要处理掉
c=(string)b;d=(string)a;
// cout<<c<<'*'<<d<<endl;
ma[c]=d;
}
while(scanf("%s",a)!=EOF)
{
string t=(string)a;
if(ma[t]!="")cout<<ma[t]<<endl;
else cout<<"eh"<<endl;
}
return 0;
}