#SHORT PROCESS NEXT by AGINTA
#compiled in CMD import java.util.Scanner;
class data{
public int at, bt, ct, tat, wt;
public String pname, tempc;
public float ntat;
}
class coba{
static int n, i, j, total_time=0;
static float avgtat=0,avgwt=0;
public static void main(String []args){
data temp;
Scanner input1 = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);
System.out.printf("masukkan input : \n");
n = input1.nextInt();
data []aa = new data[n];
for(i=0;i<n;i++){
aa[i] = new data();
System.out.printf("input : %d, at, bt\n",(i+1));
aa[i].pname = input1.nextLine();
aa[i].at = input1.nextInt();
aa[i].bt = input1.nextInt();
}
for (i=0;i<n;i++){
for (j=i;j>=1;j--){
if (aa[j].at<aa[j-1].at){
temp=aa[j-1];
aa[j-1]=aa[j];
aa[j]=temp;
}
}
}
total_time+=aa[0].at+aa[0].bt;
for(i=1;i<n;i++){
if(aa[i].at>total_time) total_time=aa[i].at;
total_time+=aa[i].bt;
}
finding(aa);
}
static void finding(data []a){
int time=0;
while(time<total_time){
j=0;
for(i=0;i<n;i++){
if(a[i].at<=time){
j=i+1;
}
}
if(j>0){
int x=0,min_bt=a[0].bt;
for (i=1;i<j;i++){
if (min_bt > a[i].bt){
x = i;
min_bt=a[i].bt;
}
}
time+=a[x].bt;
a[x].ct=time;
a[x].bt+=1000;
a[x].at+=1000;
}
else time++;
}
for (i=0;i<n;i++){
a[i].bt-=1000;
a[i].at-=1000;
}
display(a);
}
static void display (data []a){
for (i=0;i<n;i++){
a[i].tat=a[i].ct-a[i].at;
a[i].wt=a[i].tat-a[i].bt;
a[i].ntat=(float) a[i].tat/a[i].bt;
}
for (i=0;i<n;i++){
avgtat+=a[i].tat;
avgwt+=a[i].wt;
}
avgtat=avgtat/n;
avgwt=avgwt/n;
System.out.printf("pname\tat\tbt\tct\ttat\twt\tntat\n");
for (i=0;i<n;i++){
System.out.printf("%s\t%d\t%d\t%d\t%d\t%d\t%f\n",a[i].pname,a[i].at,a[i].bt,a[i].ct,a[i].tat,a[i].wt,a[i].ntat);
}
System.out.printf("avgtat=%f\navgwt=%f\n",avgtat,avgwt);
}
}
No comments:
Post a Comment