• 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 }
  • 相关阅读:
    POJ 3169 Layout(差分约束+链式前向星+SPFA)
    HDU 2680 Choose the best route(SPFA)
    PAT L2-016 愿天下有情人都是失散多年的兄妹(深搜)
    PAT L2-013 红色警报(并查集求连通子图)
    PAT L2-014 列车调度(最长上升nlogn)
    PAT L3-010 是否完全二叉搜索树(二叉搜索树)
    HRBUST 2310 Tree Painting(无向图欧拉路径的性质)
    POJ 2230 Watchcow(有向图欧拉回路)
    UVa 10054 The Necklace(无向图欧拉回路)
    UVa 1600 Patrol Robot(三维广搜)
  • 原文地址:https://www.cnblogs.com/Enumz/p/4060604.html
Copyright © 2020-2023  润新知