zoukankan      html  css  js  c++  java
  • POJ2503 -- Babelfish

    POJ2503 -- 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
    

    Hint

    Huge input and output,scanf and printf are recommended.


    我看没有人写不用sscanf()的代码,那我在这里就上传一个不用sscanf的代码吧

    AC代码

    #include <algorithm>
    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    string s, ss;
    map<string, string> mp;
    int main() {
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        string s, ss;
        while (getline(cin, s) && s.length() != 0) {
            int pos = s.find(' ');
            mp[s.substr(pos + 1, s.length() - 1)] = s.substr(0, pos);
        }
        while (cin >> s && s.length() != 0) {
            if (mp.find(s) != mp.end()) {
                cout << mp[s] << endl;
            } 
            else
                cout << "eh" << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    pycharm出现乱码
    Name-based virtual servers 给予名称的虚拟服务
    预建报为稳定版本
    nginx指令
    Module ngx_http_index_module nginx的首页模块
    我还在坚持中~
    手机端页面自适应解决方案—rem布局进阶版
    前端页面的适配使用rem换算
    js零碎知识汇总
    让input不可编辑
  • 原文地址:https://www.cnblogs.com/FrankOu/p/14326691.html
Copyright © 2011-2022 走看看