Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class LegendaryFarming {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Map<String, Integer> junk = new HashMap<>();
- Map<String, Integer> keyMaterials = new TreeMap<>();
- keyMaterials.put("motes", 0);
- keyMaterials.put("fragments", 0);
- keyMaterials.put("shards", 0);
- int[] collectedKeyValues = new int[3];
- boolean itemObtained = false;
- while (!itemObtained) {
- String[] tokens = sc.nextLine().split("\\s+");
- for (int i = 0; i < tokens.length; i+=2) {
- int quantity = Integer.parseInt(tokens[i]);
- String material = tokens[i+1].toLowerCase();
- if (keyMaterials.containsKey(material)) {
- int value = keyMaterials.get(material) + quantity;
- keyMaterials.put(material, value);
- if ("motes".equals(material)) {
- collectedKeyValues[0] += quantity;
- itemObtained = collectedKeyValues[0] >= 250;
- } else if ("fragments".equals(material)) {
- collectedKeyValues[1] += quantity;
- itemObtained = collectedKeyValues[1] >= 250;
- } else if ("shards".equals(material)) {
- collectedKeyValues[2] += quantity;
- itemObtained = collectedKeyValues[2] >= 250;
- }
- } else {
- if (!junk.containsKey(material)) {
- junk.put(material, quantity);
- } else {
- junk.put(material, junk.get(material + quantity));
- }
- }
- }
- }
- String itemName = "";
- if (collectedKeyValues[0] >= 250) {
- int value = keyMaterials.get("motes") - 250;
- keyMaterials.put("motes", 250);
- itemName = "Dragonwrath";
- } else if (collectedKeyValues[1] >= 250) {
- int value = keyMaterials.get("fragments") - 250;
- keyMaterials.put("fragments", 250);
- itemName = "Valanyr";
- } else if (collectedKeyValues[2] >= 250) {
- int value = keyMaterials.get("shard") - 250;
- keyMaterials.put("shards", 250);
- itemName = "Shadowmourne";
- }
- System.out.println(itemName + " obtained!");
- keyMaterials.entrySet().stream().sorted((a,b) -> {
- int result = Integer.compare(a.getValue(), b.getValue());
- if (result == 0) {
- result = a.getKey().compareTo(b.getKey());
- }
- return result;
- }).forEach(entry ->
- System.out.println(entry.getKey() + ": " + entry.getValue()));
- for (Map.Entry<String, Integer> entry : junk.entrySet()) {
- System.out.println(entry.getKey() + ": " + entry.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement