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

Posted Reqaw’s Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zoj 1109 Language of FatMouse(map映照容器的典型应用)相关的知识,希望对你有一定的参考价值。

题目连接:

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
 1 /*问题 输入两种语言的对照表及带查询单词,查找并输出对应的语言的单词 
 2 解题思路 使用map映照容器。用gets()读取空行为分割*/
 3 #include <cstdio>
 4 #include <iostream>
 5 #include <map>
 6 #include <string>
 7 using namespace std;
 8 
 9 int main()
10 {
11     string s;
12     map<string,string> m;
13     map<string,string>::iterator it;
14     char ss[21],s1[21],s2[21];
15     
16     /*gets函数的用法
17     gets要比cin.getline的速度快的多,单gets不能从cin中读取数据,调试不易
18     它从stdin中读取字符串,知道接受换行符或者EOF时停止,另外换行符不作为读取串的内容,读取的换行符被转化成
19     NULL值,并由此来结束字符串*/
20     
21     while(gets(ss))
22     {
23         s=ss;
24         if(s=="") break;
25         
26         sscanf(ss,"%s %s",s1,s2);
27         m[s2]=s1;//以鼠国语为键值,因为查询时输入的是鼠国语 
28     }
29     while(gets(ss))
30     {
31         s=ss;
32         it=m.find(s);
33         if(it != m.end())
34             cout<<(*it).second<<endl;
35         else
36             printf("eh\n");
37     }
38     return 0; 
39 } 

 

以上是关于zoj 1109 Language of FatMouse(map映照容器的典型应用)的主要内容,如果未能解决你的问题,请参考以下文章

zoj 1251 Box of Bricks

ZOJ - 2110 Tempter of the Bone

ZOJ-3872-Beauty of Array-思维

zoj 2818 Root of the Problem

ZOJ3872 Beauty of Array---规律 | DP| 数学能力

ZOJ 2975 Kinds of Fuwas(暴力+排列组合)