Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package my.company;
- import java.math.BigInteger;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- int startingHealth = 5800;
- int tinySporebatCost = 30;
- long totalGlowcaps = 0;
- String line = scn.nextLine();
- while (!line.equals("Sporeggar")) {
- int glowcaps = line.charAt(line.length() - 1) - '0';
- char[] enemies = line.substring(0, line.length() - 1).toCharArray();
- for (char enemy : enemies) {
- if (enemy != 'L') {
- startingHealth -= enemy;
- if (startingHealth <= 0) {
- System.out.println("Died. Glowcaps: " + totalGlowcaps);
- return;
- }
- } else {
- startingHealth += 200;
- }
- }
- totalGlowcaps += glowcaps;
- line = scn.nextLine();
- }
- System.out.println("Health left: " + startingHealth);
- if (totalGlowcaps >= tinySporebatCost) {
- System.out.println("Bought the sporebat. Glowcaps left: " + (totalGlowcaps - tinySporebatCost));
- } else {
- System.out.printf("Safe in Sporeggar, but another %d Glowcaps needed.", (tinySporebatCost - totalGlowcaps));
- }
- }
- }
- /* Tests:
- Input:
- Abcdef5
- ^&^*(8
- J3
- Sporeggar
- Output:
- Health left: 4853
- Safe in Sporeggar, but another 14 Glowcaps needed.
- In:
- ashdasdh8
- a;klsjdjak9
- alksjd3
- 1123j9
- Sporeggar
- Out:
- Health left: 3028
- Safe in Sporeggar, but another 1 Glowcaps needed.
- In:
- &*^&*^&^2
- P*&@(*&#*4
- @(*#((#8
- Sporeggar
- Out:
- Health left: 4603
- Safe in Sporeggar, but another 16 Glowcaps needed. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement