Movie Playlist
Submit solution
Points:
10 (partial)
Time limit:
1.0s
Memory limit:
64M
Authors:
Problem type
Allowed languages
Java 19, Java 8
題目說明
某影音平台想分析使用者觀看紀錄,請設計程式完成觀看資料統計。建立以下方法:
readWatchHistory()
讀取觀看紀錄,
將所有觀看分鐘數存入 ArrayList<Integer>
並回傳。calculateAverage()
計算平均觀看時間
回傳 double。
輸出格式:Average watch time: %.2f minsprintQualifiedVideos()
輸出觀看時間大於等於平均值的影片編號(影片編號從 1 開始)主程式須執行以下步驟:
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
// 讀取觀看紀錄
public static ArrayList<Integer> readWatchHistory(Scanner sc, int n) {
}
// 計算平均觀看時間
public static double calculateAverage(ArrayList<Integer> watchList) {
}
// 印出大於等於平均值的影片編號
public static void printQualifiedVideos(ArrayList<Integer> watchList, double avg) {
System.out.println("Popular videos:");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> watchList = readWatchHistory(sc, n);
double avg = calculateAverage(watchList);
System.out.printf("Average watch time: %.2f mins\n", avg);
printQualifiedVideos(watchList, avg);
System.out.println("Analysis Complete.");
}
}輸入值的格式
第一行:影片數量 N 第二行:N 個整數
輸出值的格式
- Average watch time: xx.xx mins
- Popular videos:
- 影片編號
- Analysis Complete.
sample input1
6
50 120 40 200 90 100sample output1
Average watch time: 100.00 mins
Popular videos:
2
4
6
Analysis Complete.sample input2
5
10 20 30 40 50sample output2
Average watch time: 30.00 mins
Popular videos:
3
4
5
Analysis Complete.
Comments