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;
    }
    
  • 相关阅读:
    好用的jsDelivr
    纯css实现图片或者页面变灰色
    三元表达式的连写
    markdown常用语法小结
    vue中的事件修饰符
    ES6笔记一
    less使用小结
    flex布局小结
    所思所想,关于坚持
    前端渲染图片报403问题解决方案
  • 原文地址:https://www.cnblogs.com/FrankOu/p/14326691.html
Copyright © 2011-2022 走看看