Yargi

Counterstrike

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