Babelfish Time
limit:3000MS
Memory Limit:65536KB
64bit IO Format:%i64d &%i64 U Submit Status Practice POJ 2503
Description
You are just moved from Waterloo to a big city. The people speak an incomprehensible dialect of a foreign language. Fortunately, you had a dictionary to help you understand them.
Input
Input consists of 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words . Each dictionary entry are a line containing an 中文版 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 and one word on each line. Each word in the input is a sequence of lowercase letters.
Output
Output is the message translated to 中文版, one word per line. Foreign words not in the dictionary should is translated as "eh".
Sample Input
Dog Ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Sample Output
Catehloops
Hint
Huge input and output,scanf and printf are recommended.
The meaning of the question is to translate the words
The key point is:
- Read in Data
- Mapping
Because the data exists on a line of two words and one word in two forms, we need to separate them when we read them again.
On the other hand, because the words need to be mapped, we can use mapto do a string-to-string mapping
Output with cout when final output (string format)
If further optimization time is required, the trie tree can be used
AC Code: GITHUB
1 /*2 By:ohyee3 Github:ohyee4 Homepage:http://www.oyohyee.com5 email:[email protected] ' e.com6 Blog:http://www.cnblogs.com/ohyee/7 8 かしこいかわいい? 9 エリーチカ! Ten to write out the хорошо code OH ~ One */ A -#include <cstdio> -#include <algorithm> the#include <cstring> -#include <cmath> -#include <string> -#include <iostream> +#include <vector> -#include <list> +#include <queue> A#include <stack> at#include <map> - using namespacestd; - - //DEBUG MODE - #defineDebug 0 - in //Loops - #defineREP (n) for (int o=0;o<n;o++) to + Const intMAXN =100005; - Const intMAXM = -; the *InlineintRead_string (Chars[]) { $ CharC;Panax Notoginseng inti =0; - //While (!) ( ((c = GetChar ()) = = ") | | (c >= ' a ' &&c <= ' z ' ))) the //if (c = = EOF) + //return 0; A if((c = GetChar ()) = =EOF) the return 0; + while(c = =' ') || (c >='a'&&c <='Z')) { -s[i++] =C; $c =GetChar (); $ } -S[i] =' /'; - returni; the } - Wuyi BOOLDo () { the Chartemp[maxm*2]; -map<string,string>dict; Wumap<string,string>:: iterator it; - CharA[MAXM],B[MAXM]; About $ while(read_string (temp)) { - if(strcmp (temp,"") ==0) - Break; -SSCANF (temp,"%s%s", A, b); ADICT[B] =A; + } the - while(SCANF ("\n%s", a)! =EOF) { $cout << (Dict.count (a)? Dict[a]:"EH") <<"\ n"; the } the the the return false; - } in the intMain () { the while(Do ()); About return 0; the}
POJ 2503.Babelfish