zoukankan      html  css  js  c++  java
  • POJ2503——Babelfish(map映射+string字符串)

    Babelfish

    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".
    Sample Input
    dog ogday
    cat atcay
    pig igpay
    froot ootfray
    loops oopslay

    atcay
    ittenkay
    oopslay
    Sample Output
    cat
    eh
    loops

    题目大意:

        一本猫与人类语言的翻译字典,输入一个猫的语言,输出人的语言,若没有输出eh。

    解题思路:

        map映射水过。

    Code:

     1 /*************************************************************************
     2     > File Name: poj2503.cpp
     3     > Author: Enumz
     4     > Mail: 369372123@qq.com
     5     > Created Time: 2014年10月19日 星期日 16时54分07秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<cstdio>
    10 #include<cstdlib>
    11 #include<string>
    12 #include<cstring>
    13 #include<list>
    14 #include<queue>
    15 #include<stack>
    16 #include<map>
    17 #include<set>
    18 #include<algorithm>
    19 #define MAXN 100000
    20 using namespace std;
    21 map <string,string> m;
    22 void Solve()
    23 {
    24     char tmp1[15];
    25     string str1,str2;
    26     while (gets(tmp1)&&strlen(tmp1))
    27     {
    28         int k=0;
    29         str1=str2="";
    30         while (1)
    31             if (tmp1[k]==' ')
    32             {
    33                 tmp1[k]='';
    34                 break;
    35             }
    36             else k++;
    37         str1+=tmp1;
    38         str2+=tmp1+k+1;
    39         m[str2]=str1;
    40     }
    41     while (cin>>str1)
    42         if (m[str1].size())
    43             cout<<m[str1]<<endl;
    44         else
    45             cout<<"eh"<<endl;
    46     return ;
    47 }
    48 int main()
    49 {
    50     Solve();
    51     return 0;
    52 }
  • 相关阅读:
    vaddin使用技巧
    数据库连接&数据库进程&数据库操作
    gcc编译器参数使用及解决
    smtp服务器搭建(实现本地通讯)
    jdk+tomcat+mysql搭建网站无法打开
    ie8此加载项无法恢复&网站还原错误问题解决=lr成功打开ie成功录制脚
    loadrunner打不开ie&ie默认浏览器设置方法
    判断iis是否已经安装
    loadrunner常见问题
    代码中字符串比较长时可以分行写
  • 原文地址:https://www.cnblogs.com/Enumz/p/4060604.html
Copyright © 2011-2022 走看看