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 {
- private static final Integer WIN_QUANTITY = 250;
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- LinkedHashMap<String, Integer> keyMaterials = new LinkedHashMap<String, Integer>() {{
- put("fragments", 0);
- put("motes", 0);
- put("shards", 0);
- }};
- TreeMap<String, Integer> junk = new TreeMap<>();
- String keyMaterialCollectedFirst = "";
- while (true) {
- String[] items = scn.nextLine().split(" ");
- for (int i = 0; i < items.length; i += 2) {
- int quantity = Integer.parseInt(items[i]);
- String item = items[i + 1].toLowerCase();
- if (keyMaterials.containsKey(item)) {
- keyMaterials.put(item, keyMaterials.get(item) + quantity);
- if (keyMaterials.get(item) >= WIN_QUANTITY) {
- keyMaterials.put(item, keyMaterials.get(item) - WIN_QUANTITY);
- keyMaterialCollectedFirst = item;
- break;
- }
- } else {
- if (!junk.containsKey(item)) {
- junk.put(item, 0);
- }
- junk.put(item, junk.get(item) + quantity);
- }
- }
- if (keyMaterialCollectedFirst.length() > 0) {
- break;
- }
- }
- System.out.println(getLegendary(keyMaterialCollectedFirst) + " obtained!");
- keyMaterials.entrySet().stream()
- .sorted((k1, k2) -> k2.getValue().compareTo(k1.getValue()))
- .forEach(k -> System.out.println(k.getKey() + ": " + k.getValue()));
- junk.entrySet().forEach(j -> System.out.println(j.getKey() + ": " + j.getValue()));
- }
- private static String getLegendary(String material) {
- if (material.equals("shards")) return "Shadowmourne";
- if (material.equals("fragments")) return "Valanyr";
- return "Dragonwrath";
- }
- }
- /* Tests:
- In:
- 3 Motes 5 stones 5 Shards
- 6 leathers 255 fragments 7 Shards
- Out:Valanyr obtained!
- fragments: 5
- shards: 5
- motes: 3
- leathers: 6
- stones: 5
- In:
- 8 iron
- 3 gold
- 7 silver 15 shards
- 15 onions 236 shards
- 8 freshwater
- 9 souls
- Out:
- Shadowmourne obtained!
- shards: 1
- fragments: 0
- motes: 0
- gold: 3
- iron: 8
- onions: 15
- silver: 7
- In:
- 77 heavy-leather 123 light-leather
- 789 fragments 8889 fragments 88123 motes
- Out:
- Valanyr obtained!
- fragments: 539
- motes: 0
- shards: 0
- heavy-leather: 77
- light-leather: 123
- In:
- 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
- 71 linen 71 linen 71 linen 71 linen 71 linen 71 linen
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes 15 shards 15 fragments 15 motes
- Out:
- Shadowmourne obtained!
- fragments: 240
- motes: 240
- shards: 5
- linen: 1420
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement