Language of FatMouse

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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值