MP3 のリストを実行時間順に並べ替えるために使用Collections.sort()
しています。実行時間が等しい場合はタイトルのアルファベット順に並べ替え、タイトルが等しい場合は作曲者順に並べ替えます。stdin
入力をieに入れました
入力例
3 & ピンク・フロスト&フィリップス、マーティン&234933 続編 ゲリエ・イオ・フォッシ&プッチーニ, ジャコモ&297539 ノンピウアンドライ&モーツァルト&234933 M'appari tutt'amor&Flotow、F&252905
しかし、その後、入力を介して何も思いつきません。完全に機能するはずなので、混乱しています。エラーは発生しません。
public class Lab3Algorithm {
public static void main(String args[]) throws IOException {
List<Song> songs = new ArrayList<Song>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int numOfSongsRequired = Integer.parseInt(br.readLine());
String sep = br.readLine();
String line;
while((line = br.readLine()) != null) {
String[] fields = sep.split(line);
songs.add(new Song(fields[0], fields[1], fields[2]));
}
Collections.sort(songs);
System.out.println(songs);
}
}
public class Song implements Comparable<Song> {
private final String title;
private final String composer;
private final int runningTime;
public Song(String title, String composer, String runningTime) {
this.title = title;
this.composer = composer;
this.runningTime = Integer.parseInt(runningTime);
}
public String getTitle(){
return this.title;
}
public String getComposer(){
return this.composer;
}
public int getRunningTime(){
return this.runningTime;
}
@Override
public int compareTo(Song s) {
if (runningTime > s.runningTime) {
return 1;
} else if (runningTime < s.runningTime) {
return -1;
}
int lastCmp = title.compareTo(s.title);
return (lastCmp != 0 ? lastCmp : composer.compareTo(s.composer));
}
}
誰かが私を正しい方向に向けることができれば、それは私に感謝します.