Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.NoSuchElementException;
- import java.util.Queue;
- import java.util.Scanner;
- class SLLNode<E>{
- E data;
- SLLNode<E> succ;
- SLLNode(E data, SLLNode<E> succ){
- this.data = data;
- this.succ = succ;
- }
- }
- class QueueList<E>{
- SLLNode<E> front, end;
- int lenght;
- QueueList(){
- lenght = 0;
- front = end = null;
- }
- public boolean isEmpty(){return (front == null);}
- public int size(){return lenght;}
- public E peek(){
- if(lenght > 0)
- return front.data;
- else throw new NoSuchElementException();
- }
- public void clear(){
- lenght = 0;
- front = end = null;
- }
- public void enqueue(E data){
- SLLNode<E> ins = new SLLNode<>(data, null);
- if(end != null){
- end.succ = ins;
- end = ins;
- }
- else front = end = ins;
- lenght++;
- }
- public E dequeue(){
- if(front != null){
- E ret = front.data;
- front = front.succ;
- if(front == null) end = null;
- lenght--;
- return ret;
- }
- else throw new NoSuchElementException();
- }
- public E poll(){
- if(front == null) throw new NoSuchElementException();
- return front.data;
- }
- }
- class Gragjanin{
- private String ip;
- private int lk;
- private int pasos;
- private int vd;
- public Gragjanin(String ip, int lk, int pasos, int vd){
- this.ip = ip;
- this.lk = lk;
- this.pasos = pasos;
- this.vd = vd;
- }
- public String getIp() {
- return ip;
- }
- public int getLk() {
- return lk;
- }
- public int getPasos() {
- return pasos;
- }
- public int getVd() {
- return vd;
- }
- }
- public class MVR {
- public static void main(String[] args) {
- Scanner br = new Scanner(System.in);
- int N = Integer.parseInt(br.nextLine());
- ArrayList<Gragjanin> fin = new ArrayList<Gragjanin>(N);
- QueueList<Gragjanin> l = new QueueList<>();
- QueueList<Gragjanin> p = new QueueList<>();
- QueueList<Gragjanin> v = new QueueList<>();
- for(int i=1;i<=N;i++){
- String imePrezime = br.nextLine();
- int lKarta = Integer.parseInt(br.nextLine());
- int pasos = Integer.parseInt(br.nextLine());
- int vozacka = Integer.parseInt(br.nextLine());
- Gragjanin covek = new Gragjanin(imePrezime,lKarta,pasos,vozacka);
- if(covek.getLk() == 1)
- l.enqueue(covek);
- else if(covek.getPasos() == 1)
- p.enqueue(covek);
- else v.enqueue(covek);
- }
- while(!l.isEmpty()){
- Gragjanin covek = l.dequeue();
- if(covek.getPasos() == 1)
- p.enqueue(covek);
- else if(covek.getVd() == 1)
- v.enqueue(covek);
- else fin.add(covek); //koga zavrsuva so lk, ako saka da vadi pasos odi vo red za pasos inaku proveri dali e za vd i smesti go vo toj red, inaku zavrsi
- }
- while(!p.isEmpty()){
- Gragjanin covek = p.dequeue(); //koga zavrsuva so pasos, ako mu se ceka i za vozacka odi vo toj red, inaku zavrsuva;
- if(covek.getVd() == 1)
- v.enqueue(covek);
- else fin.add(covek);
- }
- while(!v.isEmpty()) fin.add(v.dequeue()); //izvadi gi site od redot za vozacka
- for(Gragjanin x : fin){
- System.out.println(x.getIp());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement