1. 程式人生 > >資料結構基礎+STL--字典翻譯

資料結構基礎+STL--字典翻譯

Description

You have justmoved from Waterloo to a big city. The people here speak an incomprehensibledialect of a foreign language. Fortunately, you have a dictionary to help youunderstand them.

Input

Input consistsof up to 100,000 dictionary entries, followed by a blank line, followed by amessage of up to 100,000 words. Each dictionary entry is a line containing anEnglish word, followed by a space and a foreign language word. No foreign wordappears more than once in the dictionary. The message is a sequence of words inthe foreign language, one word on each line. Each word in the input is asequence of at most 10 lowercase letters.

Output

Output is themessage translated to English, one word per line. Foreign words not in thedictionary 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

利用map(雜湊)完成字典資訊的對映。

#include<map>//雜湊標頭檔案

#include<iostream>

#include<string>

using namespace std;

int main()

{

         map<string,string>m;//定義map

         chara[20],b[20];

         charstr[40];

         charstr1[20];

          m.clear();//清空

         while(gets(str)&&strlen(str)!=0)

         {

         sscanf(str,"%s%s",a,b);

         m[b]=a;

         }

         while(gets(str1))

         {

                   sscanf(str1,"%s",a);

                   if(m[a]!=" ")

                            cout<<m[a]<<endl;

                   else

                            cout<<"eh"<<endl;

         }

         return0;

}