Advertisement
mahitsy

Tiny-Sporebat

Jan 19th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. package my.company;
  2.  
  3. import java.math.BigInteger;
  4. import java.util.*;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) {
  11.         Scanner scn = new Scanner(System.in);
  12.         int startingHealth = 5800;
  13.         int tinySporebatCost = 30;
  14.         long totalGlowcaps = 0;
  15.  
  16.         String line = scn.nextLine();
  17.         while (!line.equals("Sporeggar")) {
  18.             int glowcaps = line.charAt(line.length() - 1) - '0';
  19.             char[] enemies = line.substring(0, line.length() - 1).toCharArray();
  20.             for (char enemy : enemies) {
  21.                 if (enemy != 'L') {
  22.                     startingHealth -= enemy;
  23.                     if (startingHealth <= 0) {
  24.                         System.out.println("Died. Glowcaps: " + totalGlowcaps);
  25.                         return;
  26.                     }
  27.                 } else {
  28.                     startingHealth += 200;
  29.                 }
  30.             }
  31.             totalGlowcaps += glowcaps;
  32.             line = scn.nextLine();
  33.         }
  34.  
  35.         System.out.println("Health left: " + startingHealth);
  36.  
  37.         if (totalGlowcaps >= tinySporebatCost) {
  38.             System.out.println("Bought the sporebat. Glowcaps left: " + (totalGlowcaps - tinySporebatCost));
  39.         } else {
  40.             System.out.printf("Safe in Sporeggar, but another %d Glowcaps needed.", (tinySporebatCost - totalGlowcaps));
  41.         }
  42.     }
  43. }
  44.  
  45.  
  46. /* Tests:
  47.  
  48. Input:
  49.  
  50. Abcdef5
  51. ^&^*(8
  52. J3
  53. Sporeggar
  54.  
  55. Output:
  56. Health left: 4853
  57. Safe in Sporeggar, but another 14 Glowcaps needed.
  58.  
  59. In:
  60.  
  61. ashdasdh8
  62. a;klsjdjak9
  63. alksjd3
  64. 1123j9
  65. Sporeggar
  66.  
  67. Out:
  68.  
  69. Health left: 3028
  70. Safe in Sporeggar, but another 1 Glowcaps needed.
  71.  
  72. In:
  73.  
  74. &*^&*^&^2
  75. P*&@(*&#*4
  76. @(*#((#8
  77. Sporeggar
  78.  
  79. Out:
  80.  
  81. Health left: 4603
  82. Safe in Sporeggar, but another 16 Glowcaps needed. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement