zoukankan      html  css  js  c++  java
  • [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 }
  • 相关阅读:
    Angularjs中文教程
    IE兼容性 css处理常见
    手写画板实现并转化成图片
    canvas 最基本简单的示例
    凡科 网站地址
    IOS学习之路二十二(UIAlertView获得文本框内容及添加北京图片)
    IOS学习之路十四(用TableView做的新闻客户端展示页面)
    IOS开发之路二十一(UIWebView加载本地html)
    iOS学习之路十三(动态调整UITableViewCell的高度)
    IOS学习之路十二(UITableView下拉刷新页面)
  • 原文地址:https://www.cnblogs.com/kirai/p/4761435.html
Copyright © 2011-2022 走看看