Advertisement
JosepRivaille

X13425: Distribució justa de cues

Oct 16th, 2015
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include "CuaIOParInt.hh"
  2. #include <iostream>
  3.  
  4.  
  5. int main() {
  6.   //Lectura
  7.   queue<ParInt> q;
  8.   LlegirCuaParInt(q);
  9.  
  10.   //Distribucio
  11.   queue<ParInt> q1;
  12.   queue<ParInt> q2;
  13.  
  14.   int t1 = 0;
  15.   int t2 = 0;
  16.   while (!q.empty()) {
  17.     ParInt par = q.front();
  18.     q.pop();
  19.     if (t1 <= t2) {
  20.       q1.push(par);
  21.       t1 += par.segon();
  22.     }
  23.     else {
  24.       q2.push(par);
  25.       t2 += par.segon();
  26.     }
  27.   }
  28.  
  29.   //Escriptura
  30.   EscriureCuaParInt(q1);
  31.   cout << endl;
  32.   EscriureCuaParInt(q2);  
  33. }
  34.  
  35. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement