需要帮助设计搜索歌曲的算法! [英] Need help designing an algorithm for searching songs!

查看:69
本文介绍了需要帮助设计搜索歌曲的算法!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助.我只知道JAVA顺便说一句,所以请只直接回答JAVA.这是我需要帮助的问题:

设计一种算法并将其在程序中实现,以解决以下问题,类似于MP3播放器经常遇到的问题.就我们的目的而言,歌曲由以下数据字段组成:标题(非空字符串),作曲家(一个(可能为空)字符串),运行时间(正整数).用户将调用您的程序,并给出一个文件,其中包含n首歌曲的集合以及1 <= k <= n的整数k.您的程序必须找到运行时间最长的k首歌曲,并以歌曲长度的降序输出这些歌曲.如果歌曲的运行时间相同,则我们在标题上使用字典顺序,然后在作曲家上使用总顺序.

*请注意,符号<=表示小于或等于.


所以,我不知道该怎么做,有人对如何开始我有任何想法吗?

Hi guys i need some help. I only know JAVA btw, so please only direct answers for JAVA. Here''s the question i need help with:

Devise an algorithm and implement it in a program to solve the following problem, similar to one often faced by an MP3 player. For our purposes, a song consists of the following data fields: title (a nonempty string), composer (a (possibly empty) string), running time (a positive integer). The user will call your program, giving a file containing a collection of n songs and an integer k with 1 <= k <= n. Your program must find the k songs with longest running times, and output these songs in descending order of length of song. If songs have the same running time, then we use lexicographic order on the title, and then on the composer, to get a total ordering.

*note, the symbol <= means less than or equal to.


So, i have no idea how to do this, does anyone have any idea on how to get me started? Possibly give me a sample code??

推荐答案

如果您不知道如何做作业,您的老师就是您应该告诉的人.
If you have no idea how to do your homework, your teacher is the person you should tell.


这只是一个简单的循环,遍历歌曲列表,提取每个相关字段并将结果按所需顺序排序.如果您确实需要特定Java功能方面的帮助,则应在此处 [
This is just a simple loop iterating through a list of songs, extracting each of the relevant fields and sorting the results into whatever order is required. If you really need help with specific Java functionality you should look here[^], more samples than you can shake a stick at.


这篇关于需要帮助设计搜索歌曲的算法!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆