Advertisement
Mopencio

Untitled

Aug 20th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. *
  4. * @author Usuario
  5. */
  6. public class AER521 {
  7. Scanner in = new Scanner(System.in);
  8. int viviendas;
  9. int pisos;
  10. int asistentes;
  11.  
  12. public void caso(){
  13.  
  14. Set<String> vivienda = new HashSet<>();
  15. String letra = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  16. String letraVivienda;
  17. int numPiso;
  18. int mayorPorExceso;
  19. int mitad;
  20.  
  21. for(int i = 0; i < asistentes; i++){
  22. numPiso = in.nextInt();
  23. letraVivienda = in.next().toUpperCase();
  24.  
  25. if(numPiso > pisos){
  26. throw new IllegalArgumentException("Superado el numero de pisos.");
  27. }
  28.  
  29. if(letra.substring(0, viviendas).contains(letraVivienda)){
  30. vivienda.add(numPiso+letraVivienda);
  31. }else{
  32. throw new IllegalArgumentException("Una de las viviendas no existe.");
  33. }
  34.  
  35. }
  36.  
  37. mitad = viviendas % 2;
  38. mayorPorExceso = viviendas - vivienda.size();
  39.  
  40. if(mitad != 0){
  41. if(mayorPorExceso <= vivienda.size()){
  42. System.out.println("EMPEZAMOS");
  43. }else {
  44. System.out.println("ESPERAMOS");
  45. }
  46. }else{
  47. if(mitad == 0){
  48. System.out.println("EMPEZAMOS");
  49. }else{
  50. System.out.println("ESPERAMOS");
  51. }
  52. }
  53.  
  54. }
  55.  
  56. public void run(){
  57.  
  58.  
  59. boolean centinela;
  60.  
  61. do{
  62. pisos = in.nextInt();
  63. viviendas = in.nextInt();
  64. asistentes = in.nextInt();
  65. centinela = pisos == 0 && viviendas == 0 && asistentes == 0;
  66. if(!centinela){
  67. caso();
  68. }
  69. }while(!centinela);
  70.  
  71. }
  72. /**
  73. * @param args the command line arguments
  74. */
  75. public static void main(String[] args) {
  76. new AER521().run();
  77. // TODO code application logic here
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement