Advertisement
niske

Put

Nov 27th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import java.util.LinkedList;
  2.  
  3. public class Put implements Comparable<Put>{
  4.  
  5. class Cvor {
  6. int i;
  7. int j;
  8. int vr;
  9.  
  10. public Cvor(int i, int j, int vr) {
  11. this.i = i;
  12. this.j = j;
  13. this.vr = vr;
  14. }
  15.  
  16. public String toString() {
  17. return "[" + i + ", " + j + "]";
  18. }
  19. }
  20.  
  21. LinkedList<Cvor> put = new LinkedList<Cvor>();
  22.  
  23. int vrednost = 0;
  24. int maxCv = Integer.MIN_VALUE;
  25. int brojBlaga = 0;
  26. int uzastopnoBlago = 0;
  27. int uzastopnoBlagoMax = 0;
  28.  
  29. boolean prethodniJeBlago = false;
  30.  
  31. public void dodajCvor(int i, int j, int vr) {
  32. Cvor cv = new Cvor(i, j, vr);
  33. vrednost += vr;
  34. maxCv = Math.max(maxCv, vr);
  35. if(vr != 0) {
  36. brojBlaga++;
  37. }
  38. if(prethodniJeBlago && vr != 0) {
  39. uzastopnoBlago++;
  40. }
  41. else {
  42. if(vr != 0) {
  43. prethodniJeBlago = true;
  44. uzastopnoBlago = 1;
  45. }
  46. else {
  47. prethodniJeBlago = false;
  48. uzastopnoBlagoMax = Math.max(uzastopnoBlago, uzastopnoBlagoMax);
  49. }
  50. }
  51. put.add(cv);
  52. }
  53.  
  54. public void izbrisiCvor() {
  55. put.removeLast();
  56. }
  57.  
  58. public Put kopiraj() {
  59. Put novi = new Put();
  60. for(int i = 0; i < put.size(); i++) {
  61. Cvor tmp = put.get(i);
  62. novi.dodajCvor(tmp.i, tmp.j, tmp.vr);
  63. }
  64. return novi;
  65. }
  66.  
  67. @Override
  68. public int compareTo(Put o) {
  69. return this.put.size() - o.put.size();
  70. }
  71.  
  72. public void ispisiPut() {
  73. for(int i = 0; i < put.size(); i++) {
  74. System.out.println(put.get(i));
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement