Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class LegendaryFarming {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String , Integer> specialItesm = new TreeMap<>();
- Map<String , Integer> junkItems = new TreeMap<>();
- specialItesm.put("shards",0);
- specialItesm.put("fragments",0);
- specialItesm.put("notes",0);
- boolean isObtained = false;
- while (!isObtained) {
- String input = scanner.nextLine();
- String[] tokens = input.split("\\s+");
- for (int i = 0; i < tokens.length ; i+=2) {
- int quantity = Integer.parseInt(tokens[i]);
- String item = tokens[i + 1].toLowerCase();
- if (specialItesm.containsKey(item)){
- int num = specialItesm.get(item) + quantity;
- specialItesm.put(item,num);
- }else {
- if (!junkItems.containsKey(item)){
- junkItems.put(item,quantity);
- }else {
- int secondNum = junkItems.get(item) + quantity;
- junkItems.put(item,secondNum);
- }
- }
- if (specialItesm.get("shards") >= 250){
- System.out.println("Shadowmourne obtained!");
- int num = specialItesm.get("shards") - 250;
- specialItesm.put("shards",num);
- isObtained = true;
- break;
- }else if (specialItesm.get("fragments") >= 250){
- System.out.println("Valanyr obtained!");
- int num = specialItesm.get("fragments") - 250;
- specialItesm.put("fragments",num);
- isObtained = true;
- break;
- }else if (specialItesm.get("motes") >= 250){
- System.out.println("Dragonwrath obrained!");
- int num = specialItesm.get("motes") - 250;
- specialItesm.put("motes",num);
- isObtained = true;
- break;
- }
- }
- }
- specialItesm.entrySet().stream().sorted((a,b) -> {
- if (b.getValue() - a.getValue() == 0){
- return a.getKey().compareTo(b.getKey());
- }else {
- return b.getValue() - a.getValue();
- }
- }).forEach(entry -> System.out.println(entry.getKey() + ": " + entry.getValue()));
- junkItems.forEach((key,value) -> System.out.println(key + ": " + value));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement