zoukankan      html  css  js  c++  java
  • 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
    ");
    37     }
    38     return 0; 
    39 } 
  • 相关阅读:
    7. 配置undo表空间
    8. Truncate undo表空间
    品味ZooKeeper之Watcher机制_2
    品味ZooKeeper之纵古观今_1
    《Andrew Ng深度学习》笔记5
    《Andrew Ng深度学习》笔记4
    《Andrew Ng深度学习》笔记3
    《Andrew Ng深度学习》笔记2
    《Andrew Ng深度学习》笔记1
    回归算法
  • 原文地址:https://www.cnblogs.com/wenzhixin/p/8543634.html
Copyright © 2011-2022 走看看