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,如需转载请自行联系原作者
目录
相关文章
|
机器学习/深度学习 人工智能
The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR
The Preliminary Contest for ICPC China Nanchang National Invitational K题 MORE XOR
81 0
|
机器学习/深度学习 自然语言处理 文字识别
【CS224n】(lecture5)Language Models and RNN
以往的parsing的问题: 稀疏;不完整;计算复杂(超过95%的时间都用于特征计算)
179 0
【CS224n】(lecture5)Language Models and RNN
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
104 0
|
人工智能 Go
ZOJ 3635 Cinema in Akiba
题意:一群人到电影院看电影,该电影的门票计算比较特殊,如:甲第一个拿到1号门票则位置为1,乙第二个拿票,票号也是1,则位置为2,因为1号位置已经被甲占了,乙的位置为剩下位置中的1号位置。
125 0
|
Python
lecture 1 练习
Assume that two variables, varA and varB, are assigned values, either numbers or strings.
1103 0
|
Java 语音技术 C++
(zhuan) Speech and Natural Language Processing
Speech and Natural Language Processing obtain from this link: https://github.com/edobashira/speech-language-processing A curated list of speech and natural language processing resources.

热门文章

最新文章