Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. *
  5. * @author '-Maxsuel
  6. */
  7. public class GeneraisBizantinos {
  8.  
  9. public static void main(String[] args) {
  10. Scanner ler = new Scanner(System.in);
  11. int[] generais;
  12. boolean[] isTraidor;
  13. boolean action = false; // true = atacar / false = recuar
  14.  
  15. System.out.print("Quantidade de generais: ");
  16. int qtd = ler.nextInt();
  17.  
  18. if (qtd <= 0) {
  19. System.out.println("Erro! Não pode haver traidor!");
  20. } else {
  21. generais = new int[qtd];
  22. isTraidor = new boolean[qtd];
  23. for (boolean traidor : isTraidor) {
  24. traidor = false;
  25. }
  26. System.out.print("Ordem do imperador (atacar ou recuar): ");
  27. String cmd = ler.next();
  28. switch (cmd) {
  29. case "a":
  30. case "A":
  31. case "atacar":
  32. case "Atacar":
  33. action = true;
  34. break;
  35. case "r":
  36. case "R":
  37. case "recuar":
  38. case "Recuar":
  39. action = false;
  40. break;
  41. }
  42.  
  43. int traidores = (generais.length - 1) / 3;
  44. System.out.println("Quantidade máxima de traidores: " + traidores);
  45. System.out.print("Digite a quatidade de traidores: ");
  46. int qtdTraidores = ler.nextInt();
  47. for (int i = 1; i <= qtdTraidores; i++) {
  48. System.out.print("Indique qual é o traidor (" + i + "): ");
  49. isTraidor[ler.nextInt()] = true;
  50. }
  51.  
  52. System.out.println("Broadcast.");
  53. for (int i = 0; i < generais.length; i++) {
  54. for (int j = 0; j < generais.length; j++) {
  55. if (isTraidor[i] || i != j) {
  56. generais[j] += 1;
  57. System.out.println(((i == 0) ? ("Comandante") : ("General " + j)) + " enviou " + ((!isTraidor[i]) ? "Atacar" : "Recuar") + " ao General " + j);
  58. } else if (isTraidor[i] || i != j) {
  59. generais[j] -= 1;
  60. System.out.println(((i == 0) ? ("Comandante") : ("General " + j)) + " enviou " + ((isTraidor[i]) ? "Atacar" : "Recuar") + " ao General " + j);
  61. }
  62. }
  63. }
  64. int max = -100;
  65.  
  66. for (int i = 0; i < generais.length; i++) {
  67. if (generais[i] >= max) {
  68. max = generais[i];
  69. }
  70. }
  71.  
  72. for (int i = 0; i < generais.length; i++) {
  73. if (generais[i] == max) {
  74. if (generais[i] == 0) {
  75. System.out.println("O comandante é traidor!");
  76. } else {
  77. System.out.println("General da tropa " + i + " é traidor!");
  78. }
  79. } else {
  80. if (generais[i] == 0) {
  81. if (action) {
  82. System.out.println("Comandante: ");
  83. }
  84. } else {
  85. System.out.println("General da tropa " + i + " = " + action);
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement