Poj 2503 babelfish

Source: Internet
Author: User

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.

General question:

Enter a dictionary. The dictionary format is a one-to-one ing relationship between English and foreign languages.

Then input several foreign language words and output their English translation words. If the word does not exist in the dictionary, output "eh"

 

Solution:

During input, map is used to create a ing of "foreign language English". During output, the corresponding translation is directly searched through the input characters. If the corresponding string length is 0, output eh. Otherwise, output the corresponding string

In addition, pay attention to the handling of empty rows.

 

1 # include <map> 2 # include <stdio. h> 3 # include <string> 4 using namespace STD; 5 6 int main () 7 {8 char English [11], foreign [11], STR [30]; 9 Map <string, string> translate; // record the ing from foreign to engliash 10 11 for (;) {12 gets (STR ); 13 if (STR [0] = '\ n' | STR [0] =' \ 0') {14 break; 15} 16 sscanf (STR, "% S % s", English, foreign); 17 translate [foreign] = English; 18} 19 20 while (scanf ("% s", STR )! = EOF) {21 string S = translate [STR]; 22 if (S. length () = 0) {23 printf ("Eh \ n"); 24} 25 else26 printf ("% s \ n", S. c_str (); 27} 28 return 0; 29}

 

 

Related Article

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.