zoukankan      html  css  js  c++  java
  • POJ 2503 Babelfish

    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.
     

    大致题意:

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

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

    解题思路:

    输入时再用map建立“外语 英语”的映射,输出时直接通过输入的字符查找对应的翻译,如果对应的字符串长度为 0 , 输出eh,否则,输出对应的字符串

    此外 要注意空行的处理

     1 #include<map>
     2 #include<stdio.h>
     3 #include<string>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     char english[11], foreign[11], str[30];
     9     map<string, string> translate; //记录foreign到engliash的映射
    10 
    11     for(;;){
    12         gets(str);
    13         if(str[0] == '
    ' || str[0] == '') {
    14             break;
    15         }
    16         sscanf(str, "%s%s", english, foreign);
    17         translate[foreign] = english;
    18     }
    19 
    20     while(scanf("%s", str) != EOF) {
    21         string s = translate[str];
    22         if(s.length() == 0) {
    23             printf("eh
    ");
    24         }
    25         else
    26             printf("%s
    ", s.c_str());
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    xCode中怎样保存自己的代码块
    2015-03-13---抽象工厂(附代码),
    java nio 缓冲区(一)
    MFC获取各个窗体(体)之间的指针(对象)
    自己动手写神经网络,自己真的能够动手写神经网络嘛?
    Android招財进宝手势password的实现
    QQ三方登录
    UVA 10561
    Vagi单点登录1.0
    《反脆弱》:软件业现成的鲁棒性(Robust)换了个说法变成了作者的发明,按作者的理论推导出许多可笑愚蠢的原则来
  • 原文地址:https://www.cnblogs.com/zzy9669/p/3881054.html
Copyright © 2011-2022 走看看