zoukankan      html  css  js  c++  java
  • UVA 10282 (13.08.18)

    Problem C: Babelfish

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

    Input consists of up to 100,000 dictionary entries, followed by a blankline, followed by a message of up to 100,000 words. Each dictionaryentry is a line containing an English word, followed by a space and aforeign language word. No foreign word appears more than once in thedictionary. 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 10lowercase letters.Output is the message translated to English, one word per line. Foreignwords 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
    


    题意: 这么短的题目还用我解释?

    解法: 按出题者意思是要用哈希算法, 但是可用STL中的map


    AC代码:

    #include<stdio.h>
    #include<iostream>
    #include<string>
    #include<map>
    
    using namespace std;
    
    char str1[30];
    char str2[30];
    char str[50];
    
    map<string, string> Map;
    
    int main() {
        Map.clear();
    
        while(gets(str) != NULL) {
            if(str[0] == '')
                break;
            sscanf(str, "%s %s", str1, str2);
            Map[str2] = str1;
        }
    
        while(scanf("%s", str) != EOF) {
            if(Map.find(str) != Map.end())
                cout<< Map[str] <<endl;
            else
                printf("eh
    ");
        }
        return 0;
    }


  • 相关阅读:
    session
    php增删改查,分页
    sql题
    php简单的数据增删改查
    php简单登录注册验证
    js题
    jQHTML(获取内容和属性)
    jQ效果(动画)
    Codeforces Round #460 (Div. 2): D. Substring(DAG+DP+判环)
    POJ 2891 中国剩余定理(不互素)
  • 原文地址:https://www.cnblogs.com/pangblog/p/3268837.html
Copyright © 2011-2022 走看看