Advertisement
mahitsy

LegendaryFarming

Jan 19th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 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.     private static final Integer WIN_QUANTITY = 250;
  11.  
  12.     public static void main(String[] args) {
  13.         Scanner scn = new Scanner(System.in);
  14.         LinkedHashMap<String, Integer> keyMaterials = new LinkedHashMap<String, Integer>() {{
  15.             put("fragments", 0);
  16.             put("motes", 0);
  17.             put("shards", 0);
  18.         }};
  19.         TreeMap<String, Integer> junk = new TreeMap<>();
  20.         String keyMaterialCollectedFirst = "";
  21.  
  22.         while (true) {
  23.             String[] items = scn.nextLine().split(" ");
  24.             for (int i = 0; i < items.length; i += 2) {
  25.                 int quantity = Integer.parseInt(items[i]);
  26.                 String item = items[i + 1].toLowerCase();
  27.  
  28.                 if (keyMaterials.containsKey(item)) {
  29.                     keyMaterials.put(item, keyMaterials.get(item) + quantity);
  30.  
  31.                     if (keyMaterials.get(item) >= WIN_QUANTITY) {
  32.                         keyMaterials.put(item, keyMaterials.get(item) - WIN_QUANTITY);
  33.                         keyMaterialCollectedFirst = item;
  34.                         break;
  35.                     }
  36.  
  37.                 } else {
  38.                     if (!junk.containsKey(item)) {
  39.                         junk.put(item, 0);
  40.                     }
  41.  
  42.                     junk.put(item, junk.get(item) + quantity);
  43.                 }
  44.             }
  45.  
  46.             if (keyMaterialCollectedFirst.length() > 0) {
  47.                 break;
  48.             }
  49.         }
  50.  
  51.         System.out.println(getLegendary(keyMaterialCollectedFirst) + " obtained!");
  52.  
  53.         keyMaterials.entrySet().stream()
  54.                 .sorted((k1, k2) -> k2.getValue().compareTo(k1.getValue()))
  55.                 .forEach(k -> System.out.println(k.getKey() + ": " + k.getValue()));
  56.  
  57.         junk.entrySet().forEach(j -> System.out.println(j.getKey() + ": " + j.getValue()));
  58.     }
  59.  
  60.     private static String getLegendary(String material) {
  61.         if (material.equals("shards")) return "Shadowmourne";
  62.         if (material.equals("fragments")) return "Valanyr";
  63.  
  64.         return "Dragonwrath";
  65.     }
  66. }
  67.  
  68. /* Tests:
  69.  
  70. In:
  71.  
  72. 3 Motes 5 stones 5 Shards
  73. 6 leathers 255 fragments 7 Shards
  74.  
  75. Out:Valanyr obtained!
  76. fragments: 5
  77. shards: 5
  78. motes: 3
  79. leathers: 6
  80. stones: 5
  81.  
  82. In:
  83.  
  84. 8 iron
  85. 3 gold
  86. 7 silver 15 shards
  87. 15 onions 236 shards
  88. 8 freshwater
  89. 9 souls
  90.  
  91. Out:
  92. Shadowmourne obtained!
  93. shards: 1
  94. fragments: 0
  95. motes: 0
  96. gold: 3
  97. iron: 8
  98. onions: 15
  99. silver: 7
  100.  
  101. In:
  102. 77 heavy-leather 123 light-leather
  103. 789 fragments 8889 fragments 88123 motes
  104.  
  105. Out:
  106.  
  107.  
  108. Valanyr obtained!
  109. fragments: 539
  110. motes: 0
  111. shards: 0
  112. heavy-leather: 77
  113. light-leather: 123
  114.  
  115. In:
  116.  
  117. 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen
  118. 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen
  119. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  120. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  121. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  122. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  123. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  124. 15 shards 15 fragments 15 motes
  125. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  126. 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
  127.  
  128.  
  129. Out:
  130.  
  131. Shadowmourne obtained!
  132. fragments: 240
  133. motes: 240
  134. shards: 5
  135. linen: 1420
  136.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement