• POJ 2503 -- Babelfish


     Babelfish

    Time Limit: 3000MS   Memory Limit: 65536K
    Total Submissions: 47018   Accepted: 19709

    Description

    You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

    Input

    Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

    Output

    Output is the message translated to English, one word per line. Foreign 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
    

    Sample Output

    cat
    eh
    loops
    

    Hint

    Huge input and output,scanf and printf are recommended.

    Source

     

    题意:

    输入一个字典,字典格式为“英语à外语”的一一映射关系

    然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh”

     

    解题思路:

    输入时顺便用STL的map建立 外语 =》英语 的映射,那么输出时用map.find(外语)查找,若有出现过,再输出映射,否则输出“eh”。

    这里需要注意,想要直接cout<<string ,需要引入<string>头文件,<cstring>也不行!!不然POJ编译器会Compile Error

    标红告诫自己

     1 #include<map>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<cstdio>
     5 #include<string>
     6 using namespace std;
     7 map<string,string> dir;
     8 int main()
     9 {
    10     char a[12],b[12];
    11     char temp;
    12     temp = getchar();
    13     while(temp != '
    ')
    14     {
    15         ///输入英文单词
    16         int i=0;
    17         while(temp != ' ')
    18         {
    19             a[i++] = temp;
    20             temp = getchar();
    21         }
    22         a[i] = '';
    23         ///输入外语
    24         cin>>b;
    25         getchar();//吃掉每行的换行符
    26 
    27         dir[b] = a;
    28 
    29         temp = getchar();
    30     }
    31 
    32     while(cin>>b && b[0]!='
    ')
    33     {
    34         map<string,string>::iterator iter;
    35         iter = dir.find(b);
    36         if(iter == dir.end())//没有找到
    37             cout<<"eh"<<endl;
    38         else
    39             cout<<iter->second<<endl;
    40     }
    41 
    42     return 0;
    43 }

  • 相关阅读:
    How to build Skia canvaskit
    c++ 多线程 并发 id generator 产生器
    c++ 多态 读书笔记
    c++ 各种奇门鬼爪的构造函数 和 类的初始化
    图说C++对象模型:对象内存布局详解 强烈推荐
    C++对象模型之RTTI的实现原理
    C++ cast static_cast、dynamic_cast、const_cast和reinterpret_cast(四种类型转换运算符) 强烈推荐
    Markdown 语法
    vc 编译选项 忽略crash
    chromium 编译报错 You must installWindows 10 SDK version 10.0.19041.0 including the "Debugging Tools for Windows" feature.
  • 原文地址:https://www.cnblogs.com/yxh-amysear/p/8443741.html
Copyright © 2020-2023  润新知