Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //pozezanata od voobicaenite
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- class SLLNode {
- protected int id;
- protected int plata;
- protected SLLNode succ;
- public SLLNode(int id,int plata, SLLNode succ) {
- this.id = id;
- this.plata=plata;
- this.succ = succ;
- }
- }
- class SLL {
- private SLLNode first;
- public SLL() {
- // Construct an empty SLL
- this.first = null;
- }
- public void deleteList() {
- first = null;
- }
- public int length() {
- int ret;
- if (first != null) {
- SLLNode tmp = first;
- ret = 1;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret++;
- }
- return ret;
- } else
- return 0;
- }
- public void insertFirst(int id, int plata) {
- SLLNode ins = new SLLNode(id,plata, first);
- first = ins;
- }
- public void insertLast(int id,int plata) {
- if (first != null) {
- SLLNode tmp = first;
- while (tmp.succ != null)
- tmp = tmp.succ;
- SLLNode ins = new SLLNode(id, plata, null);
- tmp.succ = ins;
- } else {
- insertFirst(id,plata);
- }
- }
- public SLLNode getFirst() {
- return first;
- }
- public SLL brisi_pomali_od(int iznos) {
- // Vasiot kod tuka
- SLLNode curr= first;
- SLLNode prev= first;
- while(curr!=null){
- if(curr.plata<iznos){
- if(curr==first){
- prev=prev.succ;
- first=curr.succ;
- curr=prev;
- }
- else {
- prev.succ = curr.succ;
- curr = prev;
- }
- }
- else{
- prev=curr;
- curr=curr.succ;
- }
- }
- return this;
- }
- public SLL sortiraj_opagacki() {
- // Vasiot kod tuka
- SLLNode curr,prev1,prev2,tmp;
- for(int i=0;i<this.length();i++){
- curr=first.succ;
- prev1=first;
- prev2=first;
- while(curr!=null){
- if(prev1.id<curr.id){
- tmp= curr.succ;
- curr.succ= prev1;
- prev1.succ= tmp;
- if(prev1==first){
- first= curr;
- }
- else{
- prev2.succ=curr;
- }
- prev2= curr;
- curr= tmp;
- }
- else{
- if(prev1!=first)
- prev2=prev2.succ;
- prev1=prev1.succ;
- curr=curr.succ;
- }
- }
- }
- return this;
- }
- public void pecati (SLL lista)
- {
- // SLLNode p=lista.first;
- // while(p!=null)
- // {
- // System.out.println(p.id+","+p.plata);
- // p=p.succ;
- // }
- if(lista.first==null) System.out.println("nema");
- else{
- SLLNode temp= lista.first;
- while(temp!=null){
- System.out.println(temp.id+" "+temp.plata);
- temp=temp.succ;
- }
- }
- }
- }
- public class SLLKompanija {
- public static void main(String[] args) throws IOException {
- SLL lista1 = new SLL();
- BufferedReader stdin = new BufferedReader(new InputStreamReader(
- System.in));
- String s = stdin.readLine();
- int N = Integer.parseInt(s);
- for (int i = 0; i < N; i++) {
- s=stdin.readLine();
- String s1=stdin.readLine();
- lista1.insertLast(Integer.parseInt(s),Integer.parseInt(s1));
- }
- s = stdin.readLine();
- lista1=lista1.brisi_pomali_od(Integer.parseInt(s));
- if(lista1!=null)
- {
- lista1=lista1.sortiraj_opagacki();
- lista1.pecati(lista1);
- }
- }
- }
- /*
- 6
- 1110
- 19000
- 213
- 25000
- 120
- 45000
- 444
- 12000
- 677
- 34000
- 1200
- 45000
- 20000
- 1200 45000
- 677 34000
- 213 25000
- 120 45000
- ---------
- 10
- 567
- 13450
- 333
- 34569
- 220
- 13450
- 440
- 45000
- 660
- 39000
- 440
- 12550
- 688
- 10000
- 778
- 41000
- 559
- 33999
- 445
- 19500
- 25000
- 778 41000
- 660 39000
- 559 33999
- 440 45000
- 333 34569
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement