Babelfish
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 28581 | Accepted: 12326 |
题目链接:http://poj.org/problem?id=2503
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
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 using namespace std; 6 struct vode 7 { 8 char eng[30]; 9 char dic[30]; 10 }; 11 struct vode g[100005]; 12 int strr ( const void *a , const void *b ) 13 { 14 return strcmp( ((vode *)a)->dic , ((vode *)b)->dic ); 15 } 16 int binsearch(int s,int t,char dic[]) 17 { 18 int low=s,high=t,mid; 19 if(s<=t) 20 { 21 mid=low+(high-low)/2; 22 if(strcmp(g[mid].dic,dic)==0)return mid; 23 if(strcmp(g[mid].dic,dic)>0) 24 return binsearch(low,mid-1,dic); 25 else 26 return binsearch(mid+1,high,dic); 27 } 28 return -1; 29 } 30 int main() 31 { 32 char dic[30]; 33 int i; 34 //下面的for循环控制字典的输入和结束,是本题的重点所在****** 35 for(i=0;dic[0]!='