Poj2503 -- babelfish (MAP ing + String string)

Source: Internet
Author: User

Babelfish

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 ogday
Cat atcay
Pig igpay
Froot ootfray
Loops oopslay

Atcay
Ittenkay
Oopslay
Sample output
Cat
Eh
Loops

Question:

A translation Dictionary of CAT and human language, inputting a cat's language, outputting a person's language, without outputting eh.

Solution:

Map ing.

Code:

1 /************************************** * *********************************** 2> File Name: poj2503.cpp 3> author: enumz 4> mail: [email protected] 5> created time: october 16: 54: 07: 6 ******************************* **************************************** */7 8 # include <iostream> 9 # include <cstdio> 10 # include <cstdlib> 11 # include <string> 12 # include <cstring> 13 # include <list> 14 # include <queue> 15 # include <stack> 16 # include <map> 17 # include <set> 18 # include <algorithm> 19 # define maxn 10000020 using namespace STD; 21 Map <string, string> m; 22 void solve () 23 {24 char tmp1 [15]; 25 string str1, str2; 26 while (gets (tmp1) & strlen (tmp1) 27 {28 int K = 0; 29 str1 = str2 = ""; 30 While (1) 31 if (tmp1 [k] = '') 32 {33 tmp1 [k] = '\ 0'; 34 break; 35} 36 else K ++; 37 str1 + = tmp1; 38 str2 + = tmp1 + k + 1; 39 m [str2] = str1; 40} 41 while (CIN> str1) 42 if (M [str1]. size () 43 cout <m [str1] <Endl; 44 else45 cout <"eh" <Endl; 46 return; 47} 48 int main () 49 {50 solve (); 51 return 0; 52}

 

Poj2503 -- babelfish (MAP ing + String string)

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.