Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Integer> materials = new LinkedHashMap<>();
- Map<String, Integer> junks = new LinkedHashMap<>();
- materials.put("shards", 0);
- materials.put("fragments", 0);
- materials.put("motes", 0);
- String winner = "";
- boolean flag = false;
- do {
- String[] data = scanner.nextLine().split("\\s+");
- for (int i = 0; i < data.length; i += 2) {
- int quantity = Integer.parseInt(data[i]);
- String material = data[i + 1].toLowerCase();
- if (!materials.containsKey(material)) {
- if (!junks.containsKey(material)) {
- junks.put(material, quantity);
- } else {
- junks.put(material, junks.get(material) + quantity);
- }
- } else {
- materials.put(material, materials.get(material) + quantity);
- if (materials.get(material) >= 250) {
- materials.put(material, materials.get(material) - 250);
- winner = material;
- flag = true;
- break;
- }
- }
- }
- } while (!flag);
- if (winner.equals("shards")){
- System.out.println("Shadowmourne obtained!");
- }else if (winner.equals("motes")){
- System.out.println("Dragonwrath obtained!");
- }else if (winner.equals("fragments")){
- System.out.println("Valanyr obtained!");
- }
- materials.entrySet()
- .stream()
- .sorted((a,b) ->{
- int sort = Integer.compare(b.getValue(), a.getValue());
- if (sort == 0){
- sort = a.getKey().compareTo(b.getKey());
- }
- return sort;
- }).forEach(e -> {
- System.out.println(String.format("%s: %d",e.getKey(),e.getValue()));
- });
- junks.entrySet().stream()
- .sorted((a,b) -> a.getKey().compareTo(b.getKey()))
- .forEach(e -> {
- System.out.println(String.format("%s: %d",e.getKey(),e.getValue()));
- });
- }
- }
Add Comment
Please, Sign In to add comment