Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.NoSuchElementException;
- class Gragjanin{
- protected String ime;
- protected int karta,pasos,vozacka;
- public Gragjanin() {
- }
- public Gragjanin(String ime, int karta, int pasos, int vozacka) {
- this.ime = ime;
- this.karta = karta;
- this.pasos = pasos;
- this.vozacka = vozacka;
- }
- }
- class SllNode<E>{
- protected E element;
- protected SllNode<E> succ;
- public SllNode(E element, SllNode<E> succ){
- this.element = element;
- this.succ = succ;
- }
- }
- class Queue<E>{
- private SllNode<E> front, rear;
- private int length;
- public Queue(){
- front = null;
- rear = null;
- length = 0;
- }
- public boolean isEmpty(){
- return (length == 0);
- }
- public int size(){
- return length;
- }
- public E peek(){
- if(length > 0)
- return front.element;
- else
- throw new NoSuchElementException();
- }
- public void enque(E x){
- SllNode<E> temp = new SllNode(x, null);
- if(length > 0){
- rear.succ = temp;
- rear = temp;
- }
- else
- front = rear = temp;
- length++;
- }
- public E deque(){
- if(length > 0){
- E temp = front.element;
- front = front.succ;
- length--;
- return temp;
- }
- else
- throw new NoSuchElementException();
- }
- @Override
- public String toString(){
- String s = new String();
- SllNode<E> temp = front;
- while(temp != null){
- s += temp.element + "\n";
- temp = temp.succ;
- }
- return s;
- }
- }
- public class MVR {
- public static void pecati(Gragjanin[] g){
- Queue<Gragjanin> lkarta = new Queue();
- Queue<Gragjanin> pasos = new Queue();
- Queue<Gragjanin> vozacka = new Queue();
- for(int i = 0; i < g.length; i++){
- if(g[i].karta == 1)
- lkarta.enque(g[i]);
- else if(g[i].pasos == 1)
- pasos.enque(g[i]);
- else if(g[i].vozacka == 1)
- vozacka.enque(g[i]);
- }
- Gragjanin temp = new Gragjanin();
- while(!lkarta.isEmpty()){
- temp = lkarta.deque();
- if(temp.pasos == 0 && temp.vozacka == 0)
- System.out.println(temp.ime);
- else if(temp.pasos == 1)
- pasos.enque(temp);
- else
- vozacka.enque(temp);
- }
- while(!pasos.isEmpty()){
- temp = pasos.deque();
- if(temp.vozacka == 0)
- System.out.println(temp.ime);
- else
- vozacka.enque(temp);
- }
- while(!vozacka.isEmpty())
- System.out.println(vozacka.deque().ime);
- }
- public static void main(String[] args) {
- Scanner br = new Scanner(System.in);
- int N = Integer.parseInt(br.nextLine());
- Gragjanin[] g = new Gragjanin[N];
- 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);
- g[i - 1] = covek;
- }
- pecati(g);
- }
- }
Add Comment
Please, Sign In to add comment