Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- /*
- 5
- 1 1 5
- 2 3 6
- 3 10 1
- 4 15 1
- 5 16 2
- */
- int main()
- {
- ll p;
- cout<<"Enter how many process are there:";
- cin>>p;
- cout<<endl;
- ll ar[p][3];
- for(ll i=0;i<p;i++){
- for(ll j=0;j<3;j++){
- cin>>ar[i][j];
- }
- }
- vector<pair<ll,ll> > vp;
- vp.push_back(make_pair(ar[0][1],ar[0][1]+ar[0][2]));
- ll prev=ar[0][1]+ar[0][2];
- for(ll i=1;i<p;i++){
- if(prev>=ar[i][1]){
- vp.push_back(make_pair(prev,prev+ar[i][2]));
- prev=prev+ar[i][2];
- }
- else{
- vp.push_back(make_pair(ar[i][1],ar[i][1]+ar[i][2]));
- prev=ar[i][1]+ar[i][2];
- }
- }
- cout<<"1 process start at "<<vp[0].first<<" and ends at "<<vp[0].second<<endl;
- for(ll i=1;i<vp.size();i++){
- if(vp[i].first==vp[i-1].second){
- cout<<i+1<<" process start at "<<vp[0].first<<" and ends at "<<vp[0].second<<endl;
- }
- else{
- cout<<"from "<<vp[i-1].second<<" to "<<vp[i].first<<"is idle time"<<endl;
- cout<<i+1<<" process start at "<<vp[0].first<<" and ends at "<<vp[0].second<<endl;
- }
- }
- ll table[p][6];
- for(ll i=0;i<p;i++){
- table[i][0]=i+1;
- table[i][1]=ar[i][1];
- table[i][2]=vp[i].first;
- table[i][3]=vp[i].second;
- table[i][4]=abs(table[i][1]-table[i][2]);
- table[i][5]=abs(table[i][3]-table[i][1]);
- }
- double awt =0, atat=0;
- for(ll i=0;i<p;i++){
- awt+=table[i][4];
- atat+=table[i][5];
- for(ll j=0;j<6;j++) cout<<table[i][j]<<" ";
- cout<<endl;
- }
- cout<<"the average waiting time is ="<<awt/p<<endl;
- cout<<"the average turn around time is ="<<atat/p<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement