Babelfish
Time Limit: 3000MS | Memory Limit: 65536K | |
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 should be translated as "eh".
Sample Input
dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay
Sample Output
cat eh loops
Hint
Huge input and output,scanf and printf are recommended.
Source
方法很多
快排加二分
hash表
还有这个模板Trie
1 #include <stdio.h> 2 #include <cstring> 3 4 struct Tire 5 { 6 int next[26];//儿子节点 7 char eng[11];//单词 8 }tt[200005]; 9 10 char en[11],fr[11]; 11 int tp = 0;//定义在main函数外会默认为0 12 13 void insert(char *x,int site) 14 { 15 if(*x!=' ')//如果不到结尾 16 { 17 if(tt[site].next[*x-'a']==0)//增加子节点 18 { 19 tt[site].next[*x-'a'] = ++tp; 20 } 21 insert(x+1,tt[site].next[*x-'a']);//继续 22 }else//抵达结尾 23 { 24 strcpy(tt[site].eng,en); 25 } 26 } 27 28 void search(char *x,int site) 29 { 30 if(*x!='