Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Компанија Problem 10 (4 / 10)
- Податоците за плати на вработените во една компанија привремено се чуваат во еднострано поврзана листа. Во секој јазол од листата се чува единствен ID на вработениот и неговата плата. Потребно е да се отстранат сите вработени со помали плати од даден износ, а остатокот да се прикажат во опаѓачки редослед во однос на ID-то. Во првиот ред од влезот е даден бројот на вработени, потоа наизменично се дадени ID и плата за секој од вработените и во последниот ред е износот во однос на кој ќе се отстрануваат вработените. На излез се печати листа (ID, плата) во опаѓачки редослед според ID на секој од вработените.
- Доколку нема вработени со плата поголема од дадената да се испечати: nema
- Име на класата: SLLKompanija
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Iterator;
- import java.util.NoSuchElementException;
- class SLL<E> {
- private SLLNode<E> first;
- public SLL() {
- // Construct an empty SLL
- this.first = null;
- }
- public void deleteList() {
- first = null;
- }
- public int length() {
- int ret;
- if (first != null) {
- SLLNode<E> tmp = first;
- ret = 1;
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret++;
- }
- return ret;
- } else
- return 0;
- }
- @Override
- public String toString() {
- String ret = new String();
- if (first != null) {
- SLLNode<E> tmp = first;
- ret += tmp + "->";
- while (tmp.succ != null) {
- tmp = tmp.succ;
- ret += tmp + "->";
- }
- } else
- ret = "Prazna lista!!!";
- return ret;
- }
- public void insertFirst(E o) {
- SLLNode<E> ins = new SLLNode<E>(o, first);
- first = ins;
- }
- public void insertAfter(E o, SLLNode<E> node) {
- if (node != null) {
- SLLNode<E> ins = new SLLNode<E>(o, node.succ);
- node.succ = ins;
- } else {
- System.out.println("Dadenot jazol e null");
- }
- }
- public void insertBefore(E o, SLLNode<E> before) {
- if (first != null) {
- SLLNode<E> tmp = first;
- if(first==before){
- this.insertFirst(o);
- return;
- }
- //ako first!=before
- while (tmp.succ != before)
- tmp = tmp.succ;
- if (tmp.succ == before) {
- SLLNode<E> ins = new SLLNode<E>(o, before);
- tmp.succ = ins;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- }
- } else {
- System.out.println("Listata e prazna");
- }
- }
- public void insertLast(E o) {
- if (first != null) {
- SLLNode<E> tmp = first;
- while (tmp.succ != null)
- tmp = tmp.succ;
- SLLNode<E> ins = new SLLNode<E>(o, null);
- tmp.succ = ins;
- } else {
- insertFirst(o);
- }
- }
- public E deleteFirst() {
- if (first != null) {
- SLLNode<E> tmp = first;
- first = first.succ;
- return tmp.element;
- } else {
- System.out.println("Listata e prazna");
- return null;
- }
- }
- public E delete(SLLNode<E> node) {
- if (first != null) {
- SLLNode<E> tmp = first;
- if(first ==node){
- return this.deleteFirst();
- }
- while (tmp.succ != node && tmp.succ.succ != null)
- tmp = tmp.succ;
- if (tmp.succ == node) {
- tmp.succ = tmp.succ.succ;
- return node.element;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- return null;
- }
- } else {
- System.out.println("Listata e prazna");
- return null;
- }
- }
- public SLLNode<E> getFirst() {
- return first;
- }
- public SLLNode<E> find(E o) {
- if (first != null) {
- SLLNode<E> tmp = first;
- while (tmp.element != o && tmp.succ != null)
- tmp = tmp.succ;
- if (tmp.element == o) {
- return tmp;
- } else {
- System.out.println("Elementot ne postoi vo listata");
- }
- } else {
- System.out.println("Listata e prazna");
- }
- return first;
- }
- public Iterator<E> iterator () {
- // Return an iterator that visits all elements of this list, in left-to-right order.
- return new LRIterator<E>();
- }
- // //////////Inner class ////////////
- private class LRIterator<E> implements Iterator<E> {
- private SLLNode<E> place, curr;
- private LRIterator() {
- place = (SLLNode<E>) first;
- curr = null;
- }
- public boolean hasNext() {
- return (place != null);
- }
- public E next() {
- if (place == null)
- throw new NoSuchElementException();
- E nextElem = place.element;
- curr = place;
- place = place.succ;
- return nextElem;
- }
- public void remove() {
- //Not implemented
- }
- }
- public void mirror(){
- if (first != null) {
- //m=nextsucc, p=tmp,q=next
- SLLNode<E> tmp = first;
- SLLNode<E> newsucc = null;
- SLLNode<E> next;
- while(tmp != null){
- next = tmp.succ;
- tmp.succ = newsucc;
- newsucc = tmp;
- tmp = next;
- }
- first = newsucc;
- }
- }
- public void merge (SLL<E> in){
- if (first != null) {
- SLLNode<E> tmp = first;
- while(tmp.succ != null)
- tmp = tmp.succ;
- tmp.succ = in.getFirst();
- }
- else{
- first = in.getFirst();
- }
- }
- }
- class SLLNode<E> {
- protected E element;
- protected SLLNode<E> succ;
- public SLLNode(E elem, SLLNode<E> succ) {
- this.element = elem;
- this.succ = succ;
- }
- @Override
- public String toString() {
- return element.toString();
- }
- }
- class Vraboten {
- int id;
- int plata;
- public Vraboten(){}
- public Vraboten(int id, int plata) {
- this.id = id;
- this.plata = plata;
- }
- public void setId(int id) {
- this.id = id;
- }
- public void setPlata(int plata) {
- this.plata = plata;
- }
- public int getId() {
- return this.id;
- }
- public int getPlata() {
- return this.plata;
- }
- }
- public class FuckingFuck {
- public static SLL<Vraboten> brisi_pomali_od_iznos(SLL<Vraboten> lista, int x) {
- SLLNode<Vraboten> d1 = lista.getFirst();
- while (d1 != null) {
- if (d1.element.plata < x) {
- lista.delete(d1);
- d1 = d1.succ;
- continue;
- } else {
- d1 = d1.succ;
- }
- }
- return lista;
- }
- public static void sortiraj_opagjacki(SLL<Vraboten> lista) {
- for (int i=0; i< lista.length(); i++) {
- SLLNode<Vraboten> d1 = lista.getFirst();
- while (d1.succ != null) {
- if (d1.element.id < d1.succ.element.id) {
- int x = d1.element.id;
- d1.element.id = d1.succ.element.id;
- d1.succ.element.id = x;
- int y = d1.element.plata;
- d1.element.plata = d1.succ.element.plata;
- d1.succ.element.plata = y;
- }
- d1 = d1.succ;
- }
- }
- SLLNode<Vraboten> d1 = lista.getFirst();
- while (d1 != null) {
- System.out.println(d1.element.id + " " + d1.element.plata);
- d1 = d1.succ;
- }
- }
- public static void main (String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- SLL<Vraboten> vraboteni = new SLL<>();
- int n = Integer.parseInt(br.readLine());
- for (int i=0; i<n; i++) {
- int id = Integer.parseInt(br.readLine());
- int plata = Integer.parseInt(br.readLine());
- Vraboten v = new Vraboten(id,plata);
- vraboteni.insertLast(v);
- }
- int iznos = Integer.parseInt(br.readLine());
- SLL<Vraboten> result = brisi_pomali_od_iznos(vraboteni,iznos);
- sortiraj_opagjacki(result);
- }
- }
- Input:
- 10
- 10
- 19000
- 18
- 25000
- 17
- 23000
- 19
- 25000
- 14
- 34000
- 55
- 23400
- 66
- 23670
- 34
- 12670
- 46
- 21300
- 33
- 34550
- 6000
- Output:
- 66 23670
- 55 23400
- 46 21300
- 34 12670
- 33 34550
- 19 25000
- 18 25000
- 17 23000
- 14 34000
- 10 19000
Add Comment
Please, Sign In to add comment