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;
    }


  • 相关阅读:
    maven的.m2文件夹
    maven parent.relativePath
    GoLang structTag说明
    Mac下如何用SSH连接远程Linux服务器
    String.split
    Laya 类列表加载优化
    JavaEE JDBC 了解数据库连接池
    JavaEE JDBC 了解JNDI
    JavaEE JDBC 事务
    JavaEE JDBC RowSet行集
  • 原文地址:https://www.cnblogs.com/pangblog/p/3268837.html
Copyright © 2011-2022 走看看