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
  • 相关阅读:
    Web.config Transformation Syntax for Web Application Project Deployment
    xcode 8.1 (8B62)真机调试配置
    主机与虚拟机互ping
    mac系统下安装mysql步骤
    iphone设备尺寸规格
    linux环境下oracle静默安装
    实现静默安装APK的方法
    mac系统下如何删除银行安全插件
    mac系统下设置eclipse的补全快捷键方法
    给Xcode增加复制行、删除行快捷键的方法
  • 原文地址:https://www.cnblogs.com/kongkaikai/p/3250339.html
Copyright © 2011-2022 走看看