(java)Poj2503:Babelfish(在线翻译)(通天鱼)

这篇博客介绍了如何使用Java解决Poj2503问题,即通过二分查找方法对大量字典条目进行高效搜索,将一种外语翻译成英语。博主提供了解题思路和参考程序,强调在处理大量数据时使用二分查找的优势。
摘要由CSDN通过智能技术生成

2503:Babelfish

总时间限制: 3000ms 内存限制: 65536kB

描述
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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as “eh”.
英文看的头疼,还是转成中文吧

2503:通天鱼

描述
您刚刚从滑铁卢搬到了一个大城市。这里的人说的是一门不可理解的外语。幸运的是,您有一本字典可以帮助您理解它们。

输入
输入最多包含100,000个字典条目,后跟一个空白行,然后是最多100,000个单词的消息。每个字典条目都是一行,其中包含一个英文单词,后跟一个空格和一个外语单词。在词典中,没有外来词出现多次。该消息是外语单词序列,每行一个单词。输入中的每个单词最多包含10个小写字母的序列。

输出
输出是将消息翻译成英语,每行一个单词。词典中未出现的外来词应翻译为“ eh”。

样例输入

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

样例输出

cat
eh
loops

解题思路
由于词条量非常的大,所以使用二分查找。对于查找字符串,要用到字符串排序。较简单得做法是建立字符串对得结构体,然后定义entry类实现comparable接口,重写cmp()方法完成排序。

参考程序

import java.util.*;

class Entry implements Comparable<Entry>{
   
	String eng;
	String frgn;
	@Override
	public int compareTo(Entry arg0){
   
		return this.frgn
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值