-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsjf.txt
34 lines (31 loc) · 772 Bytes
/
sjf.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll x,y,z,a,b,c,n;
cout<<"number of process :"<<endl;
while(cin>>n)
{
ll sm=0;
vector<pair<ll,ll> >v;
for(int i=0; i<n; i++)
{
cout<<"Process :"<<i+1<<" burst time: ";
cin>>y;
v.push_back(make_pair(y,i+1));
}
sort(v.begin(),v.end());
ll sm1=0;
for(int i=0; i<n; i++)
{
cout<<"process "<<v[i].second<<" burst time : "<<v[i].first<<" waiting time: "<<sm<<endl;
if(i!=n-1)
{
sm+=v[i].first;
sm1+=sm;
}
}
cout<<"average waiting time : "<<sm1/(double)n<<endl;
}
}