Source Code :
#include<stdio.h>
typedef struct{
int ar,bt,wt,tt,rt,_no;
}info;
info p[10];
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d",&p[i].ar,&p[i].bt);
p[i]._no=i;
}
for(i=1;i<n;i++)//sorting
{
for(j=i+1;j<=n;j++)
{
if(p[j].ar<p[i].ar)
{
info temp=p[j];
p[j]=p[i];
p[i]=temp;
}
}
}
int time=0;
for(i=1;i<=n;i++)
{
p[i].wt=p[i].rt=time-p[i].ar;
p[i].tt=p[i].wt + p[i].bt;
time=time+p[i].bt;
printf("Process: %d Ar: %d br:%d TT: %d wt:%d RT: %d\n",p[i]._no,p[i].ar,p[i].bt,p[i].tt,p[i].wt,p[i].rt);
}
printf("\n");
}
#include<stdio.h>
typedef struct{
int ar,bt,wt,tt,rt,_no;
}info;
info p[10];
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d",&p[i].ar,&p[i].bt);
p[i]._no=i;
}
for(i=1;i<n;i++)//sorting
{
for(j=i+1;j<=n;j++)
{
if(p[j].ar<p[i].ar)
{
info temp=p[j];
p[j]=p[i];
p[i]=temp;
}
}
}
int time=0;
for(i=1;i<=n;i++)
{
p[i].wt=p[i].rt=time-p[i].ar;
p[i].tt=p[i].wt + p[i].bt;
time=time+p[i].bt;
printf("Process: %d Ar: %d br:%d TT: %d wt:%d RT: %d\n",p[i]._no,p[i].ar,p[i].bt,p[i].tt,p[i].wt,p[i].rt);
}
printf("\n");
}
No comments:
Post a Comment