2011年11月18日 星期五

362 - 18,000 Seconds Remaining

檔案傳輸程式通常都會估計並顯示剩餘的傳輸時間,用來估計剩餘時間的原則為:將剩餘欲傳送的資料大小(bytes)除以前幾秒的平均傳輸率。本題請你寫程式模擬這個功能。

Input

輸入會有多組測試資料,每組資料表示一次的檔案傳輸。每組資料的第一列為一個非零的整數表示檔案的大小(bytes),接下來的每一列依序為每一秒所傳輸的資料量(bytes),傳輸的總資料量會等於檔案的大小。

當檔案大小等於0時表示測試資料結束。

Output

每組輸出資料的第一列請輸出該組資料編號及檔案的大小,接下來每5秒輸出一次剩餘檔案傳輸所需的秒數。

計算所需的秒數時請先計算前五秒的平均傳輸率(bytes/秒),若這5秒沒有傳輸任何資料表示這次的傳輸為stalled,你的程式必須輸出這種情況,否則請將剩餘資料量除以前5秒的平均傳輸率,得到剩餘秒數。剩餘秒數必須為整數,請無條件進位到整數(例如12.2進位到13)。

請在每組輸出資料的最後輸出該次傳輸共耗時多少秒,其格式請參考範例資料。

每組輸出之後請額外輸出一列空行。

Sample Input

100
10
20
20
0
10
0
10
0
10
0
20
200
60
30
100
10
50
5
5
5
5
25
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
0

Sample Output

Output for data set 1, 100 bytes:
   Time remaining: 4 seconds
   Time remaining: 5 seconds
Total time: 11 seconds

Output for data set 2, 200 bytes:
Total time: 4 seconds

Output for data set 3, 50 bytes:
   Time remaining: 1 seconds
   Time remaining: stalled
   Time remaining: stalled
   Time remaining: 0 seconds
Total time: 20 seconds


原文出處

沒有留言:

張貼留言