STL之map——解决POJ 2503

小鱼儿 2021-11-11 11:42 292阅读 0赞

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

  1. dog ogday cat atcay pig igpay froot ootfray loops oopslay
  2. atcay ittenkay oopslay

Sample Output

  1. cat
  2. eh
  3. loops
  4. #include<iostream>
  5. #include<map>
  6. using namespace std;
  7. int main()
  8. {
  9.   string str1, str2, str;
  10.   map<string, string> m;
  11.   map<string, string>::iterator it;
  12.   while(1)
  13.   {
  14.     cin>>str1;
  15.     if(getchar()!=' ')
  16.       break;
  17.     cin>>str2;
  18.     m[str2] = str1;
  19.   }
  20.   do
  21. {
  22.     it = m.find(str1);
  23.     if(it==m.end())
  24.       cout<<"eh"<<endl;
  25.     else
  26.       cout<<m[str1]<<endl;
  27.   }while(cin>>str1);
  28. return 0;
  29. }

转载于:https://www.cnblogs.com/o8le/archive/2011/09/23/2186755.html

发表评论

表情:
评论列表 (有 0 条评论,292人围观)

还没有评论,来说两句吧...

相关阅读

    相关 STLmap

    map/multimap 特性: * 具有键值和实值,根据键值自动排序 * pair的第一个元素为键值,第二个元素为实值 * 以红黑树为底层机制 ...

    相关 POJ 2503——Babelfish

    这一题也没什么思路很直接,直接用字典树存储信息,在进行查找: 优点:思路直接,速度较快      缺点:占用内存较大,建立的关系是单向的,代码较长 include

    相关 stlmap介绍

    一.Map概述  Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这