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 } 

 

转载于:https://www.cnblogs.com/wenzhixin/p/8543634.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值