《ACM程序设计》书中题目--problem b

来源:互联网 发布:程序员技能树 编辑:程序博客网 时间:2024/04/29 03:11

Description

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 ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Output for Sample Input

catehloops

解题思路:

运用map容器,将老鼠的语言与人类的语言进行关联,再次输入要翻译的老鼠的语言,在关键字中找到对应项,输出实值(人类语言)即可。

代码:

#include <bits/stdc++.h>using namespace std;int main(){ string a,b,n;  map<string,string> m;   map<string,string>::iterator p;   for(int i=0;i<100005;i++)   {   cin>>a>>b;    m[b]=a;   }  while(cin>>n)  {     p=m.find(n);     if(p!=m.end())        cout<<p->second<<endl;     else cout<<"eh"<<endl;  }  return 0;}








0 0
原创粉丝点击