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 }
  • 相关阅读:
    如何给博客园添加背景canvas线条动画背景
    过去-现在-未来
    如何将图片转化为代码图片
    css3炫酷登录页面
    图片跟随鼠标移动特效
    css3实现鼠标移入图片特效
    在线上传图片获取url
    《程序员修炼之道:从小工到专家》读后感01
    动手动脑-随机数和重载
    JAVA学习第三周
  • 原文地址:https://www.cnblogs.com/xiezhw3/p/3441953.html
Copyright © 2011-2022 走看看