ZOJ1109 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



代码:

复制代码
#include<iostream>
#include<map>
#include<string>
#include <algorithm>
using namespace std ;

int main()
{
    string strTmp;
    map<string, string> dictionary;//词典
    map<string, string>::iterator iter;
    
    //构造词典
    while(getline(cin,strTmp))
    {
        if (strTmp.compare("")==0)
        {//词典项输入结束
            break;
        }
        string strKey,strValue;
        string::iterator pos = strTmp.begin();
        pos = find(strTmp.begin(),strTmp.end(),' ');//找到空格分隔符
        copy(strTmp.begin(),pos,back_inserter(strValue));//值
        copy(pos+1,strTmp.end(),back_inserter(strKey));//键
        dictionary[strKey] = strValue;//构造词典项
    }
    //在词典中查询单词
    while(cin>>strTmp)
    {
        iter = dictionary.find(strTmp);
        if (iter!=dictionary.end())
        {//在词典中
            cout<<dictionary[strTmp]<<endl;
        }
        else
        {//不在词典中
            cout<<"eh"<<endl;
        }
    }
    return 0 ;
}
复制代码




本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/09/17/1292876.html,如需转载请自行联系原作者
目录
相关文章
|
15天前
Strange fuction(HDU--2899)
Strange fuction(HDU--2899)
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
71 0
|
存储
HDOJ/HDU 2140 Michael Scofield's letter(字符转换~)
HDOJ/HDU 2140 Michael Scofield's letter(字符转换~)
67 0
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
114 0
|
Java
HDOJ(HDU) 1720 A+B Coming(进制)
HDOJ(HDU) 1720 A+B Coming(进制)
89 0
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
103 0
|
算法 iOS开发
|
存储
HDOJ/HDU 2140 Michael Scofield&#39;s letter(字符转换~)
Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won’t be found b...
912 0