zoukankan      html  css  js  c++  java
  • Babelfish

    题目描述

    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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh". 

    样例输入

    dog ogday
    cat atcay
    pig igpay
    froot ootfray
    loops oopslay
    
    atcay
    ittenkay
    oopslay
    

    样例输出

    cat
    eh
    loops
    

    提示

    Huge input and output,scanf and printf are recommended.

     
    题目大意:事先给你一些字典中一个单词对应的字符串  然后询问一些字符串输出对应的字典单词   如果找不到输出eh
    利用STL中的map
     
    输入感觉很麻烦 转载于https://blog.csdn.net/keshuai19940722/article/details/9991699
     
    sscanf与scanf类似,都是用于输入的,只是后者以键盘(stdin)为输入源,前者以固定字符串为输入源。
    #include <iostream>
    #include <string>
    #include <map>
    #include <cstdio>
    
    using namespace std;
    const int maxn = 1005;
    
    int main()
    {
        map<string,string> m;
        char str[maxn];
        char word[maxn];
        char ans[maxn];
        while(gets(str)&&str[0]!='')
        {
            sscanf(str,"%s%s",ans,word);
            m.insert(pair<string,string>(word,ans));
        }
        char q[maxn];
        while(gets(q))
        {
            if(m.find(q)==m.end())
                cout<<"eh"<<endl;
            else
                cout<<m[q]<<endl;
        }
        return 0;
    }

    如果找不到    它返回的迭代器等于end函数返回的迭代器

  • 相关阅读:
    SICP 1.9-1.10
    SICP 1.6-1.8
    SICP 1.1-1.5
    【最小生成树】Codeforces 707B Bakery
    【数学】Codeforces 707C Pythagorean Triples
    【离线】【深搜】【树】Codeforces 707D Persistent Bookcase
    【贪心】Vijos P1615 旅行
    【字符串】【最小表示法】Vijos P1683 有根树的同构问题
    【模拟】Vijos P1005 超长数字串
    【并查集】【模拟】Codeforces 698B & 699D Fix a Tree
  • 原文地址:https://www.cnblogs.com/hao-tian/p/9439256.html
Copyright © 2011-2022 走看看