#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<pair<int,int> >v;
int x[100],wt[100];
//freopen("sjfp.txt","r",stdin);
while(1)
{
int i,j,n,a,b,sum=0;
cin>>n;
if(n==0)
{
break;
}
for(i=0;i<n;i++)
{
cin>>a>>b;
v.push_back(make_pair(a,b));
}
x[0]=0;
for(i=1;i<=n;i++)
{
x[i]=x[i-1]+v[i-1].second;
wt[i]=x[i-1];
sum=sum+wt[i];
}
cout<<"\nGrantt Chart\n"<<endl;
for(i=1;i<=n;i++)
{
cout<<"P"<<i<<"="<<x[i]<<"---> ";
}
cout<<endl<<endl;
cout<<"P\t"<<"BT\t"<<"WT"<<endl;
for(i=1;i<=n;i++)
{
cout<<i<<"\t"<<v[i-1].second<<"\t"<<wt[i]<<endl;
}
cout<<"Average Waiting Time"<<(double)sum/n<<" ms"<<endl;
}
return 0;
}
using namespace std;
int main()
{
vector<pair<int,int> >v;
int x[100],wt[100];
//freopen("sjfp.txt","r",stdin);
while(1)
{
int i,j,n,a,b,sum=0;
cin>>n;
if(n==0)
{
break;
}
for(i=0;i<n;i++)
{
cin>>a>>b;
v.push_back(make_pair(a,b));
}
x[0]=0;
for(i=1;i<=n;i++)
{
x[i]=x[i-1]+v[i-1].second;
wt[i]=x[i-1];
sum=sum+wt[i];
}
cout<<"\nGrantt Chart\n"<<endl;
for(i=1;i<=n;i++)
{
cout<<"P"<<i<<"="<<x[i]<<"---> ";
}
cout<<endl<<endl;
cout<<"P\t"<<"BT\t"<<"WT"<<endl;
for(i=1;i<=n;i++)
{
cout<<i<<"\t"<<v[i-1].second<<"\t"<<wt[i]<<endl;
}
cout<<"Average Waiting Time"<<(double)sum/n<<" ms"<<endl;
}
return 0;
}
0 comments:
Post a Comment