Advertisement
Guest User

Untitled

a guest
May 27th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.77 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class HuxleyCode {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner keyboard = new Scanner(System.in);
  8.         String especialRU = keyboard.nextLine().substring(3);
  9.         String especialA2 = keyboard.nextLine().substring(7);
  10.         String comando = "";
  11.  
  12.         while (keyboard.hasNextLine()) {
  13.             comando = keyboard.nextLine();
  14.             if (!comando.contains(":")) {
  15.                 comando = comando + ":@#234!@#)(*";
  16.             }
  17.  
  18.             Aluno aluno = new Aluno(comando);
  19.             System.out.println(aluno.sort(especialRU, especialA2));
  20.            
  21.         }
  22.     }
  23. }
  24.  
  25.  
  26. class FilaA2 {
  27.     private String pessoa;
  28.     private FilaA2 proximo;
  29.     static int contador;
  30.     static String entrou;
  31.     static String saiu;
  32.  
  33.     FilaA2(){
  34.         this.pessoa = null;
  35.         this.proximo = null;
  36.     }
  37.  
  38.     public String insert(String pessoa) {
  39.         if (this.pessoa == null) {
  40.             contador++;
  41.             this.pessoa = pessoa;
  42.             entrou = this.pessoa;
  43.             this.proximo = new FilaA2();
  44.             return entrou + " foi para a fila da Area 2";
  45.         } else {
  46.             return this.proximo.insert(pessoa);
  47.         }
  48.     }
  49.  
  50.     public String remove() {
  51.         if (this.pessoa != null) {
  52.             contador--;
  53.             saiu = this.pessoa;
  54.             this.pessoa = this.proximo.pessoa;
  55.             this.proximo = this.proximo.proximo;
  56.             return saiu + " almocou na Area 2 e esta voltando pra aula";
  57.         } else {
  58.             return "Nao ha mais ninguem para comer aqui";
  59.         }
  60.     }
  61.  
  62.     public int contador() {
  63.         return contador;
  64.     }
  65.  
  66. }
  67.  
  68.  
  69. class FilaRU {
  70.     private String pessoa;
  71.     private FilaRU proximo;
  72.     static int contador;
  73.     static String entrou;
  74.     static String saiu;
  75.  
  76.     FilaRU(){
  77.         this.pessoa = null;
  78.         this.proximo = null;
  79.     }
  80.  
  81.     public String insert(String pessoa) {
  82.         if (this.pessoa == null) {
  83.             contador++;
  84.             this.pessoa = pessoa;
  85.             entrou = this.pessoa;
  86.             this.proximo = new FilaRU();
  87.             return entrou + " foi para a fila do RU";
  88.         } else {
  89.             return this.proximo.insert(pessoa);
  90.         }
  91.     }
  92.  
  93.     public String remove() {
  94.         if (this.pessoa != null) {
  95.             contador--;
  96.             saiu = this.pessoa;
  97.             this.pessoa = this.proximo.pessoa;
  98.             this.proximo = this.proximo.proximo;
  99.             return saiu + " almocou no RU e esta voltando pra aula";
  100.         } else {
  101.             return "Nao ha mais ninguem para comer aqui";
  102.         }
  103.     }
  104.  
  105.     public int contador() {
  106.         return contador;
  107.     }
  108.  
  109. }
  110.  
  111.  
  112. class Aluno {
  113.  
  114.     private String aluno;
  115.     private String preferencia;
  116.     private Aluno proximo;
  117.     private static FilaRU filaru = new FilaRU();
  118.     private static FilaA2 filaa2 = new FilaA2();
  119.  
  120.     Aluno(String comando){
  121.         this.aluno = comando.substring(0, comando.indexOf(':'));
  122.         this.preferencia = comando.substring(comando.indexOf(":") + 1, comando.length());
  123.     }
  124.  
  125.     public String sort(String especialRU, String especialA2) {
  126.         if (this.preferencia != null && this.aluno != null) {
  127.            
  128.             if (this.preferencia.equals(especialRU)) {
  129.                
  130.                 if (especialRU.equals(especialA2)) {
  131.                     if (filaru.contador() >= filaa2.contador()) {
  132.                         return filaa2.insert(this.aluno);
  133.                     } else {
  134.                         return filaru.insert(this.aluno);
  135.                     }
  136.                 } else {
  137.                     return filaru.insert(this.aluno);
  138.                 }
  139.                
  140.             } else if (this.preferencia.equals(especialA2)) {
  141.                
  142.                 if (especialRU.equals(especialA2)) {
  143.                     if (filaru.contador() >= filaa2.contador()) {
  144.                         return filaa2.insert(this.aluno);
  145.                     } else {
  146.                         return filaru.insert(this.aluno);
  147.                     }
  148.                 } else {
  149.                     return filaa2.insert(this.aluno);
  150.                 }
  151.                
  152.             } else if (this.aluno.equals("SAIU")) {
  153.                 if (this.preferencia.equals("AREA2")) {
  154.                     return filaa2.remove();
  155.                 } else if (this.preferencia.equals("RU")) {
  156.                     return filaru.remove();
  157.                 }
  158.             } else {
  159.                 if (filaru.contador() >= filaa2.contador()) {
  160.                     return filaa2.insert(this.aluno);
  161.                 } else {
  162.                     return filaru.insert(this.aluno);
  163.                 }
  164.             }
  165.         }
  166.         return proximo.sort(especialRU, especialA2);
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement