Poj 2503 babelfish

Source: Internet
Author: User
Babelfish
Time limit:3000 Ms   Memory limit:65536 K
Total submissions:32169   Accepted:13832

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 shocould be translated as "eh ".

Sample Input

dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Sample output

catehloops

Hint

Huge input and output, scanf and printf are recommended.

Source

Waterloo local 2001.09.22 many methods add binary hash tables with this template Trie
1 # include <stdio. h> 2 # include <cstring> 3 4 struct tire 5 {6 int next [26]; // son node 7 char Eng [11]; // Word 8} TT [200005]; 9 10 char en [11], FR [11]; 11 int TP = 0; // The default value is 012 13 void insert (char * X, int site) 14 {15 if (* X! = '\ N') // if the end is not 16 {17 if (TT [site]. next [* X-'a'] = 0) // Add the subnode 18 {19 TT [site]. next [* X-'a'] = ++ TP; 20} 21 insert (x + 1, TT [site]. next [* X-'a']); // continue 22} else // arrival end 23 {24 strcpy (TT [site]. eng, en); 25} 26} 27 28 void search (char * X, int site) 29 {30 if (* X! = '\ 0') 31 {32 If (TT [site]. Next [* X-'a'] = 0) // cannot be found !!! 33 {34 printf ("Eh \ n"); 35 return; 36} 37 search (x + 1, TT [site]. next [* X-'a']); // continue 38} else // found 39 {40 printf ("% s \ n", TT [site]. eng); 41} 42} 43 44 int main () 45 {46 char STR [1, 100]; 47 While (gets (STR) & STR [0]) // read the string from the stdin stream until it receives a linefeed or EOF, and save the read results in the character array pointed to by the buffer pointer. 49 // The linefeed is not used as the content of the read string. The linefeed is converted to an empty character '\ 0' and ends the string. 50 {51 sscanf (STR, "% S % s", en, fr); // read data that matches the specified format from a string. 52 insert (FR, 0); 53} 54 while (scanf ("% s", Fr )! = EOF) {55 search (FR, 0); 56} 57 Return 0; 58}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.