Didart

Counter Strike

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