1806:词典( 3.9数据结构之C++STL)

来源:互联网 发布:sql增加数据 编辑:程序博客网 时间:2024/06/10 18:33

1806:词典

总时间限制: 3000ms 内存限制: 65536kB
描述
你旅游到了一个国外的城市。那里的人们说的外国语言你不能理解。不过幸运的是,你有一本词典可以帮助你。

输入
首先输入一个词典,词典中包含不超过100000个词条,每个词条占据一行。每一个词条包括一个英文单词和一个外语单词,两个单词之间用一个空格隔开。而且在词典中不会有某个外语单词出现超过两次。词典之后是一个空行,然后给出一个由外语单词组成的文档,文档不超过100000行,而且每行只包括一个外语单词。输入中出现单词只包括小写字母,而且长度不会超过10。
输出
在输出中,你需要把输入文档翻译成英文,每行输出一个英文单词。如果某个外语单词不在词典中,就把这个单词翻译成“eh”。
样例输入
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay
样例输出
cat
eh
loops

好久没一次性就对了了,但是也是在看书的基础上,map的用法还是要经常熟悉的,很有用,而且发现map

#include<iostream>#include<map>#include<string>#include<iterator>#include<cstdio>#include<algorithm>using namespace std;//http://noi.openjudge.cn/ch0309/1806/map<string,string> m;map<string,string>::iterator it;string a,b,c;char tmp;int main(){    while((tmp=cin.get())!='\n'){        cin.putback(tmp);        cin>>a>>b;        m[b]=a;        cin.get();    }    while(cin>>c){        it=m.find(c);        if(it!=m.end())cout<<it->second<<endl;        else cout<<"eh"<<endl;    }}
原创粉丝点击