找回密码
 注册
查看: 1348|回复: 5

一道国外名校的Java题,求救!4月1号结止!

[复制链接]
发表于 2006-3-30 19:33:38 | 显示全部楼层 |阅读模式
/**
任务2:移动电话 65/100 MARKS
一些移动电话有一个用数字电话键盘简短的打文字信息的模式。在这个模式中,系统应用一个已知单词的字典,一串阿拉伯数字之后,输入系统检索并显示在字典中可能匹配的单词。这个电话键盘的英语字母表如下:

__________________________
| 1        | 2 abc | 3 def |
--------------------------
| 4 ghi    | 5 jkl | 6 mno |
--------------------------
| 7 pqrs   | 8 tuv | 9 wxyz|
--------------------------
| 0 (space)|       |       |
--------------------------

你的任务是用一个得到的字典写一个显示所有的可能匹配按照给出的阿拉数字顺序的程序通过使用一个给出的字典。相应的阿拉伯数字的顺序对应相应的单词,用阿拉伯数字0代表空格。倒置0被忽略,并且多重连续的0处理成一个单独的0。为每个非零的数字串,显示字典匹配的单词,当有大多数可用的匹配单词汇时,显示所有在字典中的匹配的单词并用|竖线分隔开。如果没有匹配单词,显示一串星号的同样长度。
例如
一个字典含有单独的i,loud,love,programming的单词这个阿拉伯数字序列是:0040568300077647266464077770
i (loud|love) programming ****'

注意:这个功能不该干扰相同移动电话的功能,例如,有些移动电话,当你按一个字母显示所有字典的单词,从那个字母开始你能选择每一个单词。

输入格式:
输入包含一个或多个情况,每个情况包括字典中许可的单词和一系列数字串,翻译成文本信息。字典包含1到100个单词,每行一个单词,在增加字典时不用排序。每个单词包括1到30个小写字母。为任意给的非零的数字串,在字典中要有超出10个可匹配的单词。字典的结尾用#标志,数字串由字典翻译成文本信息,每行不超出10个单词。每个信息行包括1到100个数字。至少要有一个非零的数字。信息结尾是一个单独的#,输入结束表明是空字典(个字典零个单词)。输入将包括最多25种情况。

SAMPLE INPUT:

i
loud
love
programming
#
0040568300077647266464077770
#
a
game
go
golf
good
hand
hold
hole
home
in
me
of
to
#
2046630426306304653
46086020466304663
#
#


输出格式:
为每种情况输出一行包含大写单词 SET 跟随着一个空格,然后这情况序号,从1开始,接着输出翻译的文本信息,每行一条信息。

SAMPLE OUTPUT:

SET 1
i (loud|love) programming ****
SET 2
a (good|home) (game|hand) (me|of) (golf|hold|hole)
(in|go) to a (good|home) (good|home)


此题可能是说,输入一些英文单词,以#号结束,再输入一组数字以#号结束。程序自动比较英文和数字,0为空格,一样的代码用(...|...)分开,多余的数字输******填补。再输入#号退出程序。

*/


经鄙人翻译,如此而是,鄙人编的总是不行,可能是鄙人一直无法理解题意而至,请教一套较全的Java编程,鄙人的仅编写了如下东东:

import java.io.*;
import java.util.*;

public class Task2{
public static void main(String[] args){
     String inputline[] = new String[100];
     Scanner keyboard = new Scanner(System.in);
     for (int i =0; i < 100; i++){
         inputline = keyboard.nextLine();
         System.out.println(inputline);
         if (inputline == "#") i=100;

         
       }
     }

}

原题为
TASK 2: MOBILE PHONES - 65 / 100 MARKS

--------------------------------------------------------------------------------

Some mobile phones have a shortcut mode for typing text messages using the numerical phone keypad. In this mode, the system uses a dictionary of known words. After a sequence of digits is entered the system checks for and displays all possible matches in the dictionary. The phone keypad for the English alphabet is as follows:

1 2 abc 3 def
4 ghi 5 jkl 6 mno
7 pqrs 8 tuv 9 wxyz
0 (space)     

Your task is to write a program that displays all possible matches for given digit sequences, using a given dictionary. A digit sequence corresponds to a sequence of words, with zero digits ('0') indicating spaces. Leading and trailing zeros are ignored, and multiple consecutive embedded zeros are treated as a single zero. For each sequence of non-zero digits, display the matching word from the dictionary. When more than one match is available, display all matches in dictionary order between round parentheses and separated by bars ('|'). If there is no matching word, display a sequence of asterisks ('*') of the same length. For example, with a dictionary consisting solely of the words 'i', 'loud', 'love', 'programming', the digit sequence

'0040568300077647266464077770'

will be displayed as the text

'i (loud|love) programming ****'
Note: this functionality should not be confused with other similar mobile phone functionality. For example, some mobile phones, when you select a letter, display all the words of the dictionary that start with that letter, so you can select one.

INPUT FORMAT
The input will consist of one or more scenarios, each scenario consisting of a dictionary of permitted words and a series of digit sequences to be interpreted as text messages. The dictionary consists of 1 to 100 words, one word per line, in increasing dictionary order, with no duplicates. Each word consists of 1 to 30 lowercase letters. For any given non-zero digit sequence there will be no more than 10 matching words in the dictionary. The end of the dictionary is indicated by a line consisting of a single '#'. The digit sequences to interpret as text messages follow the dictionary, one per line, and are no more than 10. Each message line consists of 1 to 100 digits, with at least 1 non-zero digit. The end of messages is indicated by a line consisting of a single '#'. The end of input is indicated by an empty dictionary (a dictionary with zero words). Input will consist of at most 25 scenarios.

SAMPLE INPUT:

i
loud
love
programming
#
0040568300077647266464077770
#
a
game
go
golf
good
hand
hold
hole
home
in
me
of
to
#
2046630426306304653
46086020466304663
#
#



OUTPUT FORMAT
For each scenario output a line consisting of the word 'SET' (all uppercase) followed by a space and then the scenario number, starting with 1. Following this output the list of interpreted text messages, one message per line.

SAMPLE OUTPUT:

SET 1
i (loud|love) programming ****
SET 2
a (good|home) (game|hand) (me|of) (golf|hold|hole)
(in|go) to a (good|home) (good|home)



  


--------------------------------------------------------------------------------

Acknowledgement: the tasks of this assignment were adapted from a set of problems developed by the ACM.

Last Updated: 16/03/2006 11:50:48
发表于 2006-3-31 10:01:13 | 显示全部楼层
学习数据结构与算法.
回复

使用道具 举报

发表于 2006-3-31 10:41:52 | 显示全部楼层
好像是应用一个经典的通过2叉树实现的编码算法(哈夫曼算法?),记不起来了,楼主自己
找本数据结构书查吧
回复

使用道具 举报

发表于 2006-4-1 10:18:43 | 显示全部楼层
am I late?
you can make a map first,every index node is an digital string,and the correspond  element is a list a word the input present to U. whenever a decimal string comes,you find in the map ,and output the result.
am i clear.
回复

使用道具 举报

发表于 2006-4-1 17:01:57 | 显示全部楼层
横看竖看都像作业。。。
回复

使用道具 举报

发表于 2006-4-2 22:11:34 | 显示全部楼层
为什么现在我们很多人基础不行啊。。。
    那搞Linux不是很累??
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-7 03:07 , Processed in 0.029400 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表