zoukankan      html  css  js  c++  java
  • sicily 数据结构 1014. Translation

    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".

     

    其实真的没有什么好说的,本来我在想时间上会不会TM掉,要不要想个公式来构造哈希。。后来发现完全没必要,因为计算哈希的时间还是很可观的。另外一个就是在想要不要用C来写,后来还是发现。。。直接map就可以搞定了。。。被坑。。。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string>
     4 #include <map>
     5 
     6 using namespace std;
     7 
     8 void split(string& aString, string& key, string& word) {
     9     int i = aString.find(' ');
    10 
    11     string tek(aString, 0, i);
    12     string tew(aString, i + 1);
    13     key = tek;
    14     word = tew;
    15 }
    16 int main(int argc, char const *argv[])
    17 {
    18     string aString, word, key;
    19     map<string, string> dict;
    20     while (getline(cin, aString)) {
    21         if (aString.size() == 0)
    22             break;
    23 
    24         split(aString, key, word);
    25         dict[word] = key;
    26     }
    27 
    28     while (cin >> aString) {
    29         if (dict[aString] == "")
    30             printf("eh
    ");
    31         else
    32             cout << dict[aString] << endl;
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    使用boost的type_index打印数据类型
    display:flex;下的子元素width无效问题
    three.js 材质翻转
    qt5 打包exe执行文件
    脚本免交互生成秘钥
    脚本连接主机创建用户expect
    expect用法
    免密登录脚本expect
    shell变量的定义规则
    shell变量如何定义?
  • 原文地址:https://www.cnblogs.com/xiezhw3/p/3441953.html
Copyright © 2011-2022 走看看