Babelfish

题目描述

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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh". 

 

样例输入

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

 

样例输出

cat
eh
loops

 

提示

Huge input and output,scanf and printf are recommended.

 
题目大意:事先给你一些字典中一个单词对应的字符串  然后询问一些字符串输出对应的字典单词   如果找不到输出eh
利用STL中的map
 
输入感觉很麻烦 转载于https://blog.csdn.net/keshuai19940722/article/details/9991699
 
sscanf与scanf类似,都是用于输入的,只是后者以键盘(stdin)为输入源,前者以固定字符串为输入源。
#include <iostream>
#include <string>
#include <map>
#include <cstdio>

using namespace std;
const int maxn = 1005;

int main()
{
    map<string,string> m;
    char str[maxn];
    char word[maxn];
    char ans[maxn];
    while(gets(str)&&str[0]!='\0')
    {
        sscanf(str,"%s%s",ans,word);
        m.insert(pair<string,string>(word,ans));
    }
    char q[maxn];
    while(gets(q))
    {
        if(m.find(q)==m.end())
            cout<<"eh"<<endl;
        else
            cout<<m[q]<<endl;
    }
    return 0;
}

如果找不到    它返回的迭代器等于end函数返回的迭代器

posted @ 2018-08-07 20:29  zangzang  阅读(125)  评论(0编辑  收藏  举报