Babelfish
Time Limit: 3000MS |
|
Memory Limit: 65536K |
Total Submissions: 37238 |
|
Accepted: 15879 |
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: The use of sscanf here, very ingenious;
Code:
1#include <stdio.h>2#include <algorithm>3#include <string.h>4 using namespacestd;5 Const intmaxn=100010;6 structnode{7 Charen[ -],ei[ -];//No words open small ... 8 };9 Node DT[MAXN];Ten intCMP (Node A,node b) { One returnstrcmp (A.ei,b.ei) <0; A } - intErfen (Char*x,intLintR) { - while(l<=R) { the intMid= (l+r) >>1; - if(!STRCMP (dt[mid].ei,x))returnmid; - if(strcmp (dt[mid].ei,x) >0) r=mid-1; - ElseL=mid+1; + } - return-1; + } A intMain () { at intdm=0; - Charstr[ -]; - Node A; - while(gets (str)) { - if(str[0]==' /') Break; -SSCANF (str,"%s%s", A.en,a.ei);//It's ingenious here ... indt[dm++]=A; - } toSort (dt,dt+dm,cmp); + while(~SCANF ("%s", str)) { - intT=erfen (str,0, dm-1); the if(t==-1) puts ("EH"); * Elseprintf"%s\n", dt[t].en); $ }Panax Notoginseng return 0; -}
Babelfish (two minutes)