• [POJ2503]Babelfish


    题目链接:http://poj.org/problem?id=2503

     
     

    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
    

    Hint

    Huge input and output,scanf and printf are recommended.

    Source

    STL撸过,重要的是输入的处理。

     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <cmath>
     7 #include <queue>
     8 #include <map>
     9 #include <stack>
    10 #include <list>
    11 #include <vector>
    12 #include <cctype>
    13 
    14 using namespace std;
    15 
    16 typedef map<string, string> mss;
    17 typedef pair<string, string> pss;
    18 mss dic;
    19 pss tmp;
    20 char a[110];
    21 char b[110];
    22 char buf[80];
    23 
    24 int main() {
    25     // freopen("in", "r", stdin);
    26     // ios::sync_with_stdio(false);
    27     while(gets(buf)) {
    28         int flag = 0;
    29         int cnt = 0;
    30         int sflag = 0;
    31         for(int i = 0; buf[i]; i++) {
    32             if(flag) {
    33                 if(sflag && buf[i] == ' ') {
    34                     continue;
    35                 }
    36                 b[cnt++] = buf[i];
    37             }
    38             else {        
    39                 if(buf[i] != ' ') {
    40                     a[cnt++] = buf[i];
    41                     sflag = 1;
    42                 }
    43                 else {
    44                     flag = 1;
    45                     cnt = 0;
    46                 }
    47             }
    48         }
    49         tmp = make_pair(b, a);
    50         dic.insert(tmp);
    51         if(!flag) {
    52             break;
    53         }
    54         memset(a, 0, sizeof(a));
    55         memset(b, 0, sizeof(b));
    56         memset(buf, 0, sizeof(buf));
    57     }
    58     // for(mss::iterator it = dic.begin(); it != dic.end(); it++) {
    59     //     cout << it->first << " " << it->second << endl;
    60     // }
    61     while(~scanf("%s", buf)) {
    62         if(dic.find(buf) != dic.end()) {
    63             // cout << dic[buf] << endl;
    64             printf("%s
    ", dic[buf].data());
    65         }
    66         else {
    67             printf("eh
    ");
    68         }
    69     }
    70     return 0;
    71 }
  • 相关阅读:
    tortoisegit 还原到某个版本
    AndroidStudio2021/3版 gradle7.0环境 自定义输出apk路径
    docker镜像打包save,载入load,启动run
    Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli)
    windows10下载网址
    win10开启CPU虚拟化导致蓝屏信息
    swagger-ui.html
    git初始化
    node-sass 把变量导出给js共享。
    openlayers moveend getEventCoordinate
  • 原文地址:https://www.cnblogs.com/kirai/p/4761435.html
Copyright © 2020-2023  润新知