• 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;
    }
    
  • 相关阅读:
    vue实战(3):底部导航显示、搭建各模块静态页面、添加登录页页面与路由
    vue实战(2):初始化项目、搭建底部导航路由
    hexo
    移动端自适应
    vue过场动画
    获取 TypeScript
    TypeScript 与 JavaScript 的区别
    api封装使用
    vue学习
    dom的增删改
  • 原文地址:https://www.cnblogs.com/FrankOu/p/14326691.html
Copyright © 2020-2023  润新知