zoj 1109 Language of FatMouse(map映照容器的典型应用)

2022-12-22,,,,

题目连接:

acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109 

题目描述:

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
 /*问题 输入两种语言的对照表及带查询单词,查找并输出对应的语言的单词
解题思路 使用map映照容器。用gets()读取空行为分割*/
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std; int main()
{
string s;
map<string,string> m;
map<string,string>::iterator it;
char ss[],s1[],s2[]; /*gets函数的用法
gets要比cin.getline的速度快的多,单gets不能从cin中读取数据,调试不易
它从stdin中读取字符串,知道接受换行符或者EOF时停止,另外换行符不作为读取串的内容,读取的换行符被转化成
NULL值,并由此来结束字符串*/ while(gets(ss))
{
s=ss;
if(s=="") break; sscanf(ss,"%s %s",s1,s2);
m[s2]=s1;//以鼠国语为键值,因为查询时输入的是鼠国语
}
while(gets(ss))
{
s=ss;
it=m.find(s);
if(it != m.end())
cout<<(*it).second<<endl;
else
printf("eh\n");
}
return ;
}

zoj 1109 Language of FatMouse(map映照容器的典型应用)的相关教程结束。

《zoj 1109 Language of FatMouse(map映照容器的典型应用).doc》

下载本文的Word格式文档,以方便收藏与打印。