UVA - 362
题目介绍:
A feature of many file transfer programs is the ability to estimate the amount of time remaining in
the transfer. These programs estimate the time remaining based on the number of bytes left to be
transferred and the rate of transfer in previous seconds. You are to write a program to simulate this
behavior.
大意:
统计当前速度,估计接下来的所需时间。能用乘法就不要用除法,吃了亏。
AC代码:
#include<iostream>
using namespace std;
int main(){
int n,Case=1;
while(scanf("%d",&n)&&n){
printf("Output for data set %d, %d bytes:\n",Case++,n);
int k,sum,temp;
sum=k=temp=0;
int num=0;
while(sum<n){
int x;
scanf("%d",&x);
num++;
sum+=x;
temp+=x;
k++;
if(k==5){
k=0;
if(temp!=0){
int remain=5*(n-sum)%temp;
int ans=5*(n-sum)/temp+(remain>0);
printf(" Time remaining: %d seconds\n",ans);
temp=0;
}
else printf(" Time remaining: stalled\n");
}
}
printf("Total time: %d seconds\n\n",num);
}
return 0;
}