kristina7

RoundRobin

Jan 25th, 2017
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.PriorityQueue;
  5. import java.util.Queue;
  6.  
  7.  
  8. public class RoundRobin {
  9.     public static void main(String[] args) throws  IOException {
  10.     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  11.     Queue<Proces> redica = new PriorityQueue<>();
  12.     int N = Integer.parseInt(br.readLine());
  13.     for (int i = 0; i < N; i++) {
  14.         String []s = br.readLine().split(" ");
  15.         Proces p = new Proces(s[0],Integer.parseInt(s[1]),Integer.parseInt(s[2]),0);
  16.         redica.add(p);
  17.         }
  18.    
  19.     int q = Integer.parseInt(br.readLine());
  20.     br.close();
  21.     int brojac = 0;
  22.     while(redica.size() > 0){
  23.         Proces tmp = redica.poll();
  24.         if(q < tmp.izvrsuvanje)
  25.         {
  26.             int iz = tmp.izvrsuvanje - q;
  27.             brojac++;
  28.             redica.add(new Proces(tmp.name,iz,tmp.pristignuvanje,brojac));
  29.            
  30.         }
  31.         System.out.print(tmp.name+" ");
  32.            
  33.        
  34.     }
  35.     }
  36.    
  37. }
  38. class Proces implements Comparable<Proces>{
  39.        
  40.     String name;
  41.         int izvrsuvanje;
  42.         int pristignuvanje;
  43.         int priority;
  44.         public Proces(String name,int i, int p, int pri) {
  45.             this.name = name;
  46.             this.izvrsuvanje = i;
  47.             this.pristignuvanje = p;
  48.             this.priority = pri;
  49.         }
  50.         @Override
  51.         public int compareTo(Proces p) {
  52.             if(this.priority > p.priority)
  53.                 return 1;
  54.             else if(this.priority < p.priority)
  55.                 return -1;
  56.             else{
  57.                 if(this.pristignuvanje > p.pristignuvanje)
  58.                     return 1;
  59.                 else if(this.pristignuvanje < p.pristignuvanje)
  60.                     return -1;
  61.                 else{
  62.                     if(this.izvrsuvanje > p.izvrsuvanje)
  63.                         return -1;
  64.                     else
  65.                         return 1;
  66.                 }
  67.             }
  68.            
  69.         }
  70.        
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment