Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class LegendaryFarming {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Integer> materials = new TreeMap<>();
- materials.put("shards", 0);
- materials.put("fragments", 0);
- materials.put("motes", 0);
- Map<String, Integer> junks = new TreeMap<>();
- boolean isOver = false;
- while (!isOver) {
- String input = scanner.nextLine();
- String[] inputData = input.split(" ");
- for (int index = 0; index < inputData.length; index += 2) {
- int quantity = Integer.parseInt(inputData[index]);
- String material = inputData[index + 1].toLowerCase(Locale.ROOT);
- if (material.equals("shards") || material.equals("fragments")
- || material.equals("motes")) {
- int currentQuantity = materials.get(material);
- materials.put(material, currentQuantity + quantity);
- if (materials.get(material) >= 250) {
- if (material.equals("shards")) {
- System.out.println("Shadowmourne obtained!");
- } else if (material.equals("fragments")) {
- System.out.println("Valanyr obtained!");
- } else {
- System.out.println("Dragonwrath obtained!");
- }
- materials.put(material, materials.get(material) - 250);
- isOver = true;
- break;
- }
- } else {
- if (!junks.containsKey(material)) {
- junks.put(material, quantity);
- } else {
- int currentQuantity = junks.get(material);
- junks.put(material, currentQuantity + quantity);
- }
- }
- }
- }
- materials.entrySet().stream()
- .sorted((entry1, entry2) -> entry2.getValue()
- .compareTo(entry1.getValue()))
- .forEach(entry -> System.out.printf("%s: %d%n", entry.getKey(), entry.getValue()));
- junks.entrySet()
- .forEach(entry -> System.out.println(entry.getKey() + ": " + entry.getValue()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment