问!谁能帮我解这道java题?感谢····
登录 | 论坛导航 -> 华新鲜事 -> 社会百科 | 本帖共有 7 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:tonymmm (等级:2 - 初出茅庐,发帖:212) 发表:2003-10-09 02:05:23  楼主  关注此帖
问!谁能帮我解这道java题?感谢····
write a program that reads an unspecified number of integers and finds the one that has the most occurrences. your input ends when the input is -1.for example, if you entered 2 3 40 3 5 4 7 3 3 2 -1, the number 3 occurred most often. enter one number at a time. if several numbers have the most occurrences, all of them should be reported. for example, if both 9 and 3 occur the same times, both should be reported.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:辰星 (等级:12 - 登峰造极,发帖:6227) 发表:2003-10-09 03:43:03  2楼
Try his
Implement in Linked List, with each node containing a number and its frequency.

Whenever a number is input, it tries to find it if it's in the List.

If so, add its frequency by 1.

If not, add a tail containing the number into the Linked List and set its frequency to 1.

At the end, scan the whole List and try to find out the nodes containing max frequency.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:香陵居士 (等级:16 - 好恐怖呀,发帖:22662) 发表:2003-10-09 09:41:50  3楼
If there is no memory limitation
You can use a array which is large enough. Use the input number as index and update the corresponding element.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:今夜独自发呆 (等级:5 - 略有小成,发帖:1855) 发表:2003-10-09 10:44:31  4楼
B+ tree better...
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:cigar (等级:2 - 初出茅庐,发帖:296) 发表:2003-10-09 16:37:49  5楼
Try hisImplement in Linked List, with each node containing a number and its frequency. Whenever a number is input, it tries to find it if it's in the List. If so, add its frequency by 1. If not, add a tail containing the number into the Linked List and set its frequency to 1. At the end, scan the whole List and try to find out the nodes containing max frequency.
Linear search is expensive
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:辰星 (等级:12 - 登峰造极,发帖:6227) 发表:2003-10-09 23:37:09  6楼
Linear search is expensive
But for his question it is ok.
it's not such like a complex system
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
作者:豫北闲人 (等级:3 - 略知一二,发帖:376) 发表:2003-10-10 11:51:21  7楼 评分:
Use Hashtable
Convert the input value and the occurrence as Integer, use input value as Key and occurrence as Value, for every input, if you can find in the hashtable, increase the occurrence, if not, just put it in. The rest should be very easy.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表
论坛导航 -> 华新鲜事 -> 社会百科 | 返回上一页 | 本主题共有 7 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码