Didart

Legendary Farming

Nov 5th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class LegendaryFarming {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         Map<String, Integer> materials = new TreeMap<>();
  8.  
  9.         materials.put("shards", 0);
  10.         materials.put("fragments", 0);
  11.         materials.put("motes", 0);
  12.  
  13.         Map<String, Integer> junks = new TreeMap<>();
  14.  
  15.         boolean isOver = false;
  16.         while (!isOver) {
  17.             String input = scanner.nextLine();
  18.             String[] inputData = input.split(" ");
  19.             for (int index = 0; index < inputData.length; index += 2) {
  20.                 int quantity = Integer.parseInt(inputData[index]);
  21.                 String material = inputData[index + 1].toLowerCase(Locale.ROOT);
  22.                 if (material.equals("shards") || material.equals("fragments")
  23.                         || material.equals("motes")) {
  24.  
  25.                     int currentQuantity = materials.get(material);
  26.                     materials.put(material, currentQuantity + quantity);
  27.                     if (materials.get(material) >= 250) {
  28.                         if (material.equals("shards")) {
  29.                             System.out.println("Shadowmourne obtained!");
  30.                         } else if (material.equals("fragments")) {
  31.                             System.out.println("Valanyr obtained!");
  32.                         } else {
  33.                             System.out.println("Dragonwrath obtained!");
  34.                         }
  35.                         materials.put(material, materials.get(material) - 250);
  36.                         isOver = true;
  37.                         break;
  38.                     }
  39.                 } else {
  40.                     if (!junks.containsKey(material)) {
  41.                         junks.put(material, quantity);
  42.                     } else {
  43.                         int currentQuantity = junks.get(material);
  44.                         junks.put(material, currentQuantity + quantity);
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.         materials.entrySet().stream()
  50.                 .sorted((entry1, entry2) -> entry2.getValue()
  51.                         .compareTo(entry1.getValue()))
  52.         .forEach(entry -> System.out.printf("%s: %d%n", entry.getKey(), entry.getValue()));
  53.  
  54.         junks.entrySet()
  55.                 .forEach(entry -> System.out.println(entry.getKey() + ": " + entry.getValue()));
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment