Advertisement
Guest User

01 zadach

a guest
Apr 7th, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class first {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int initialEnergy = Integer.parseInt(scanner.nextLine());
  8.         int counter = 0;
  9.  
  10.         for (int i = 1; i <= initialEnergy; i++) {
  11.             String input = scanner.nextLine();
  12.             if ("End of battle".equals(input)) {
  13.                 break;
  14.             }
  15.  
  16.             int distance = Integer.parseInt(input);
  17.             initialEnergy -= distance;
  18.  
  19.             if (initialEnergy >= 0) {
  20.                 if (i % 3 == 0) {
  21.                     initialEnergy += i;
  22.                 }
  23.                 counter++;
  24.             }else {
  25.                 break;
  26.             }
  27.         }
  28.  
  29.         if (initialEnergy <= 0) {
  30.             System.out.printf("Not enough energy! Game ends with %d won battles and %d energy", counter, initialEnergy);
  31.         } else {
  32.             System.out.printf("Won battles: %d. Energy left: %d", counter, initialEnergy);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement