Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- *
- * @author '-Maxsuel
- */
- public class GeneraisBizantinos {
- public static void main(String[] args) {
- Scanner ler = new Scanner(System.in);
- int[] generais;
- boolean[] isTraidor;
- boolean action = false; // true = atacar / false = recuar
- System.out.print("Quantidade de generais: ");
- int qtd = ler.nextInt();
- if (qtd <= 0) {
- System.out.println("Erro! Não pode haver traidor!");
- } else {
- generais = new int[qtd];
- isTraidor = new boolean[qtd];
- for (boolean traidor : isTraidor) {
- traidor = false;
- }
- System.out.print("Ordem do imperador (atacar ou recuar): ");
- String cmd = ler.next();
- switch (cmd) {
- case "a":
- case "A":
- case "atacar":
- case "Atacar":
- action = true;
- break;
- case "r":
- case "R":
- case "recuar":
- case "Recuar":
- action = false;
- break;
- }
- int traidores = (generais.length - 1) / 3;
- System.out.println("Quantidade máxima de traidores: " + traidores);
- System.out.print("Digite a quatidade de traidores: ");
- int qtdTraidores = ler.nextInt();
- for (int i = 1; i <= qtdTraidores; i++) {
- System.out.print("Indique qual é o traidor (" + i + "): ");
- isTraidor[ler.nextInt()] = true;
- }
- System.out.println("Broadcast.");
- for (int i = 0; i < generais.length; i++) {
- for (int j = 0; j < generais.length; j++) {
- if (isTraidor[i] || i != j) {
- generais[j] += 1;
- System.out.println(((i == 0) ? ("Comandante") : ("General " + j)) + " enviou " + ((!isTraidor[i]) ? "Atacar" : "Recuar") + " ao General " + j);
- } else if (isTraidor[i] || i != j) {
- generais[j] -= 1;
- System.out.println(((i == 0) ? ("Comandante") : ("General " + j)) + " enviou " + ((isTraidor[i]) ? "Atacar" : "Recuar") + " ao General " + j);
- }
- }
- }
- int max = -100;
- for (int i = 0; i < generais.length; i++) {
- if (generais[i] >= max) {
- max = generais[i];
- }
- }
- for (int i = 0; i < generais.length; i++) {
- if (generais[i] == max) {
- if (generais[i] == 0) {
- System.out.println("O comandante é traidor!");
- } else {
- System.out.println("General da tropa " + i + " é traidor!");
- }
- } else {
- if (generais[i] == 0) {
- if (action) {
- System.out.println("Comandante: ");
- }
- } else {
- System.out.println("General da tropa " + i + " = " + action);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement