fork download
  1.  
  2. /*CODE WRITTEN BY MAYANK PADIA*/
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. typedef long long ll;
  6. typedef double ld;
  7. #define pb push_back
  8. #define F first
  9. #define S second
  10. #define mp make_pair
  11. int main(){
  12. #ifndef ONLINE_JUDGE
  13. freopen("input.txt","r",stdin);
  14. freopen("output.txt","w",stdout);
  15. #endif
  16. ios::sync_with_stdio(0); cin.tie(0);
  17. ll n,t;
  18. cout<<"Enter Number of Processes\n";
  19. cin>>n;
  20. queue<pair<string,ll> > readyQueue,r1;
  21. cout<<"Enter 1. Process Name 2. Burst Time 3. Arrival Time\n";
  22. vector<pair<ll,pair<string,ll> > > v;
  23. for (int i = 0; i < n; ++i)
  24. {
  25. ll x,y;
  26. string s;
  27. cin>>s>>x>>y;
  28. v.pb(mp(y,mp(s,x)));
  29. }
  30. sort(v.begin(),v.end());
  31. for (int i = 0; i < n; ++i)
  32. {
  33. ll x,y;
  34. string s;
  35. readyQueue.push(mp(v[i].S.F,v[i].S.S));
  36. }
  37. ll t1=0;
  38. ld averaget1=0,averaget2=0;
  39. for (int i = 0; i < n; ++i)
  40. {
  41. cout<<"readyQueue:\n";
  42. while(!readyQueue.empty())
  43. {/* code */
  44. cout<<readyQueue.front().F<<" "<<readyQueue.front().S<<endl;
  45. r1.push(mp(readyQueue.front().F,readyQueue.front().S));
  46. readyQueue.pop();
  47. }
  48. while(!r1.empty()){
  49. readyQueue.push(mp(r1.front().F,r1.front().S));
  50. r1.pop();
  51. }
  52. cout<<"\n\n";
  53. pair<string,ll> p;
  54. p.F=readyQueue.front().F;
  55. p.S=readyQueue.front().S;
  56. readyQueue.pop();
  57. t1=max(t1,v[i].F);
  58. cout<<"Process Schedule: At time: "<<endl<<p.F<<" "<<t1<<endl;
  59. cout<<"Processcompleted TAT: Waiting Time: "<<endl<<p.F<<" "<<t1+p.S-v[i].F<<" "<<t1-v[i].F<<endl;
  60. t1+=p.S;
  61. averaget1+=t1-v[i].F;
  62. averaget2+=t1-p.S-v[i].F;
  63. }
  64. cout<<"\n\n\n"<<"average Waiting Time: "<<averaget2/n<<endl;
  65. cout<<"Average TurnAroundTime:"<<averaget1/n<<endl;
  66. #ifndef ONLINE_JUDGE
  67. cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
  68. #endif
  69. return 0;
  70. }
Success #stdin #stdout 0s 15256KB
stdin
Standard input is empty
stdout
Enter Number of Processes
Enter 1. Process Name  2. Burst Time  3. Arrival Time



average Waiting Time:   -nan
Average TurnAroundTime:-nan