Advertisement
Ivelin_Arsov

CounterStrike

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