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