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}