Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CounterStrike {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int initialEnergy = Integer.parseInt(scan.nextLine());
- String distance = scan.nextLine();
- int countWinBattles = 0;
- while (!distance.equals("End of battle")) {
- int currentDistance = Integer.parseInt(distance);
- if (currentDistance <= initialEnergy) {
- initialEnergy -= currentDistance;
- countWinBattles++;
- if(countWinBattles % 3 == 0){
- initialEnergy += countWinBattles;
- }
- } else if (initialEnergy - currentDistance < 0){
- System.out.printf("Not enough energy! Game ends with %d won battles and %d energy",countWinBattles,initialEnergy);
- return;
- }
- distance = scan.nextLine();
- }
- System.out.printf("Won battles: %d. Energy left: %d",countWinBattles,initialEnergy);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement