Advertisement
lameski

round robin

Jan 24th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import java.util.Collections;
  2. import java.util.Comparator;
  3. import java.util.LinkedList;
  4. import java.util.PriorityQueue;
  5. import java.util.Scanner;
  6.  
  7. public class RoundRobin {
  8. public static void main(String[] args) {
  9. Scanner in = new Scanner(System.in);
  10.  
  11. int n = Integer.parseInt(in.nextLine());
  12.  
  13. LinkedList<Proces> ll = new LinkedList<Proces>();
  14.  
  15.  
  16.  
  17. for(int i=0; i<n; i++)
  18. {
  19. String line = in.nextLine();
  20. String [] parts = line.split(" ");
  21. ll.add(new Proces(parts[0],Integer.parseInt(parts[1])
  22. , Integer.parseInt(parts[2])));
  23. }
  24.  
  25. int odzemach = Integer.parseInt(in.nextLine());
  26.  
  27. ll.sort(Comparator.comparing(Proces::getPristig)
  28. .thenComparing(Proces::getIzvrs_));
  29.  
  30. while(ll.size()>0)
  31. {
  32. Proces pr = ll.removeFirst();
  33. System.out.print(pr.ime+" ");
  34. pr.obnovi(odzemach);
  35. if(pr.getIzvrs()>0)
  36. ll.add(pr);
  37. }
  38. }
  39. }
  40.  
  41. class Proces
  42. {
  43. String ime;
  44. int izvrs, pristig;
  45.  
  46. Proces()
  47. {
  48. this.ime = "";
  49. this.izvrs = 0;
  50. this.pristig = 0;
  51. }
  52. Proces(String ime, int izvrs, int pristig)
  53. {
  54. this.ime = ime;
  55. this.izvrs = izvrs;
  56. this.pristig = pristig;
  57. }
  58.  
  59. int getPristig()
  60. {
  61. return pristig;
  62. }
  63. int getIzvrs()
  64. {
  65. return izvrs;
  66. }
  67. int getIzvrs_()
  68. {
  69. return -izvrs;
  70. }
  71. void obnovi(int n)
  72. {
  73. this.izvrs-=n;
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement