Advertisement
StefiIOE

Kompanija

Jul 24th, 2020
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. import static java.lang.Integer.parseInt;
  6.  
  7.  
  8. class SLLNode {
  9.     protected int id;
  10.     protected int plata;
  11.     protected SLLNode succ;
  12.  
  13.     public SLLNode(int id,int plata, SLLNode succ) {
  14.         this.id = id;
  15.         this.plata=plata;
  16.         this.succ = succ;
  17.     }
  18.  
  19.  
  20. }
  21.  
  22. class SLL {
  23.     private SLLNode first;
  24.  
  25.     public SLL() {
  26.         // Construct an empty SLL
  27.         this.first = null;
  28.     }
  29.  
  30.     public void deleteList() {
  31.         first = null;
  32.     }
  33.  
  34.     public int length() {
  35.         int ret;
  36.         if (first != null) {
  37.             SLLNode tmp = first;
  38.             ret = 1;
  39.             while (tmp.succ != null) {
  40.                 tmp = tmp.succ;
  41.                 ret++;
  42.             }
  43.             return ret;
  44.         } else
  45.             return 0;
  46.  
  47.     }
  48.  
  49.  
  50.     public void insertFirst(int id, int plata) {
  51.         SLLNode ins = new SLLNode(id,plata, first);
  52.         first = ins;
  53.     }
  54.  
  55.     public void insertLast(int id,int plata) {
  56.         if (first != null) {
  57.             SLLNode tmp = first;
  58.             while (tmp.succ != null)
  59.                 tmp = tmp.succ;
  60.             SLLNode ins = new SLLNode(id, plata, null);
  61.             tmp.succ = ins;
  62.         } else {
  63.             insertFirst(id,plata);
  64.         }
  65.     }
  66.  
  67.     public SLLNode getFirst() {
  68.         return first;
  69.     }
  70.  
  71.  
  72.     public SLL brisi_pomali_od(int iznos) {
  73.         //int nov=iznos;
  74.         SLL rezultat = new SLL();
  75.         SLLNode first=this.getFirst(); //????
  76.         while (first!=null){
  77.             if(first.plata>=iznos){
  78.             rezultat.insertLast(first.id,first.plata);
  79.             }
  80.             first=first.succ;
  81.         }
  82.         return rezultat;
  83.     }
  84.  
  85.     public SLL sortiraj_opagacki() {
  86.         SLLNode first=this.getFirst();
  87.         int tmp;
  88.         SLLNode previous=null;
  89.         SLLNode current=null;
  90.         SLLNode next=null;
  91.         if(first==null){
  92.             System.out.println("nema");
  93.             return this;
  94.         }
  95.         for(int i = 0; i < 10 ; i ++){
  96.             first=getFirst();
  97.             while (first!=null && first.succ!=null){
  98.                 current=first;
  99.                 next=first.succ;
  100.                 if(current.id<next.id){
  101.  
  102.                     tmp=current.id;
  103.                     current.id=next.id;
  104.                     next.id=tmp;
  105.  
  106.                     tmp=current.plata;
  107.                     current.plata=next.plata;
  108.                     next.plata=tmp;
  109.                 }
  110.                 first=first.succ;
  111.             }
  112.  
  113.         }
  114.         return this;
  115.     }
  116.     public void pecati (SLL lista)
  117.     {
  118.         SLLNode p=lista.first;
  119.         while(p!=null)
  120.         {
  121.             System.out.println(p.id+" "+p.plata);
  122.             p=p.succ;
  123.         }
  124.     }
  125.  
  126. }
  127. public class SLLKompanija {
  128.     public static void main(String[] args) throws IOException {
  129.  
  130.         SLL lista1 = new SLL();
  131.         BufferedReader stdin = new BufferedReader(new InputStreamReader(
  132.                 System.in));
  133.         String s = stdin.readLine();
  134.         int N = parseInt(s);
  135.  
  136.         for (int i = 0; i < N; i++) {
  137.             s=stdin.readLine();
  138.             String s1=stdin.readLine();
  139.             lista1.insertLast(parseInt(s), parseInt(s1));
  140.         }
  141.         s = stdin.readLine();
  142.  
  143.         lista1=lista1.brisi_pomali_od(parseInt(s));
  144.         if(lista1!=null)
  145.         {
  146.             lista1=lista1.sortiraj_opagacki();
  147.             lista1.pecati(lista1);
  148.         }
  149.  
  150.     }
  151. }
  152.  
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement