• 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 }
  • 相关阅读:
    模拟实现ajax加载框
    京东晒单的js实现
    微信分享js代码(转载)
    css模拟实现selec下拉框
    网页端实现输入卡号四字隔开
    返回顶部的动态显示与隐藏
    js等比例缩放图片(转载)
    css模拟实现checkbox
    quartz的使用 Mr
    Spring声明式事务配置管理方法 Mr
  • 原文地址:https://www.cnblogs.com/Enumz/p/4060604.html
Copyright © 2020-2023  润新知