zoukankan      html  css  js  c++  java
  • Babelfish

    Time Limit: 1000MS Memory limit: 65536K
    题目描述
    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

    这个题觉得不难,本意是字典树,自己不会,各种水,用数组也可以做,但是一定会超时

    用map水了一下,感觉空行结束太没有爱了害我纠结了半天

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<map>
     4 using namespace std;
     5 int main()
     6 {
     7     map<string,string>mapp;//map,不解释
     8     char ch,s[15],p[15];
     9     while(scanf("%c",&ch))
    10     {
    11         if(ch=='
    ')break;//解决那个烦人的空行结束
    12         s[0]=ch;
    13         scanf("%s",s+1);
    14         scanf("%s",p);
    15         getchar();
    16         mapp.insert(pair<string,string>(p,s));//插入语句
    17     }
    18     map<string,string>::iterator iter;//声明迭代器,别问我什么用,我也不知道
    19     while(~scanf("%s",s))
    20     {
    21         iter=mapp.find(s);//查找啊
    22         if(iter!=mapp.end())//这个说明找到了
    23             printf("%s
    ",iter->second.c_str());//打印出来,别忘了后面的.c_str();
    24         else
    25             printf("eh
    ");
    26     }
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    MySQL
    用python自动复制粘贴excel表里某一列的数据到另一个表中
    python操作excel小试牛刀
    python- 安装扩展包
    15分钟用ppt制作桌面整理四格壁纸
    R-算术运算符
    R-变量
    R-函数/语法-整合版
    MySQL-函数-整合版
    Python_图片对比问题汇总
  • 原文地址:https://www.cnblogs.com/kongkaikai/p/3250339.html
Copyright © 2011-2022 走看看