Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Fundamentals._20_Associative_Arrays.MoreExercise;
- import java.util.*;
- import java.util.stream.Collectors;
- public class _3_Legendary_Farming {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- input = input.toLowerCase();
- String [] inputArr = input.split(" ");
- String obtainad = "";
- Map <String, Integer> collected = new TreeMap<>();
- Map <String, Integer> finalCollect = new TreeMap<>();
- Map <String, Integer> junk = new TreeMap<>();
- for (int i = 0; i <inputArr.length ; i++) {
- if ( i%2!=0 && (inputArr[i].equals("shards") ||
- inputArr[i].equals("fragments") ||
- inputArr[i].equals("motes") )){
- if (collected.containsKey(inputArr[i])){
- collected.put(inputArr[i],collected.get(inputArr[i])+
- Integer.parseInt(inputArr[i-1]));
- }else {
- collected.put(inputArr[i],Integer.parseInt(inputArr[i-1]));
- }
- }else if (i%2!=0 && (!inputArr[i].equals("shards") ||
- !inputArr[i].equals("fragments") ||
- !inputArr[i].equals("motes"))){
- if (i%2==0 && junk.containsKey(inputArr[i])){
- junk.put(inputArr[i],collected.get(inputArr[i])+
- Integer.parseInt(inputArr[i-1]));
- }else {
- junk.put(inputArr[i],Integer.parseInt(inputArr[i-1]));
- }
- }
- if (collected.containsKey("shards") && collected.get("shards")>=250) {
- System.out.println("Shadowmourne obtained!");
- collected.put("shards",collected.get("shards")-250);
- collected.putIfAbsent("fragments",0);
- collected.putIfAbsent("motes",0);
- Map<String, Integer> sortedByCount;
- sortedByCount = collected.entrySet()
- .stream()
- .sorted((Map.Entry.<String, Integer>comparingByValue().reversed()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
- sortedByCount.forEach((s,u) -> System.out.println(s+": "+u));
- junk.forEach((s,u) -> System.out.println(s+": "+u));
- break;
- } else if (collected.containsKey("fragments") && collected.get("fragments")>=250){
- System.out.println("Valanyr obtained!");
- collected.put("fragments",collected.get("fragments")-250);
- collected.putIfAbsent("shards",0);
- collected.putIfAbsent("motes",0);
- Map<String, Integer> sortedByCount;
- sortedByCount = collected.entrySet()
- .stream()
- .sorted((Map.Entry.<String, Integer>comparingByValue().reversed()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
- sortedByCount.forEach((s,u) -> System.out.println(s+": "+u));
- junk.forEach((s,u) -> System.out.println(s+": "+u));
- break;
- }else if (collected.containsKey("motes") && collected.get("motes")>=250){
- System.out.println("Dragonwrath obtained!");
- collected.put("motes",collected.get("motes")-250);
- collected.putIfAbsent("fragments",0);
- collected.putIfAbsent("shards",0);
- Map<String, Integer> sortedByCount;
- sortedByCount = collected.entrySet()
- .stream()
- .sorted((Map.Entry.<String, Integer>comparingByValue().reversed()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
- sortedByCount.forEach((s,u) -> System.out.println(s+": "+u));
- junk.forEach((s,u) -> System.out.println(s+": "+u));
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement