Advertisement
petar088

3.Legendary_Farming

Apr 16th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. package Fundamentals._20_Associative_Arrays.MoreExercise;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class _3_Legendary_Farming {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String input = scanner.nextLine();
  11. input = input.toLowerCase();
  12. String [] inputArr = input.split(" ");
  13.  
  14. String obtainad = "";
  15. Map <String, Integer> collected = new TreeMap<>();
  16. Map <String, Integer> finalCollect = new TreeMap<>();
  17. Map <String, Integer> junk = new TreeMap<>();
  18.  
  19. for (int i = 0; i <inputArr.length ; i++) {
  20. if ( i%2!=0 && (inputArr[i].equals("shards") ||
  21. inputArr[i].equals("fragments") ||
  22. inputArr[i].equals("motes") )){
  23.  
  24. if (collected.containsKey(inputArr[i])){
  25. collected.put(inputArr[i],collected.get(inputArr[i])+
  26. Integer.parseInt(inputArr[i-1]));
  27. }else {
  28. collected.put(inputArr[i],Integer.parseInt(inputArr[i-1]));
  29. }
  30.  
  31.  
  32. }else if (i%2!=0 && (!inputArr[i].equals("shards") ||
  33. !inputArr[i].equals("fragments") ||
  34. !inputArr[i].equals("motes"))){
  35. if (i%2==0 && junk.containsKey(inputArr[i])){
  36. junk.put(inputArr[i],collected.get(inputArr[i])+
  37. Integer.parseInt(inputArr[i-1]));
  38. }else {
  39. junk.put(inputArr[i],Integer.parseInt(inputArr[i-1]));
  40. }
  41.  
  42. }
  43. if (collected.containsKey("shards") && collected.get("shards")>=250) {
  44. System.out.println("Shadowmourne obtained!");
  45. collected.put("shards",collected.get("shards")-250);
  46.  
  47. collected.putIfAbsent("fragments",0);
  48. collected.putIfAbsent("motes",0);
  49.  
  50.  
  51.  
  52. Map<String, Integer> sortedByCount;
  53. sortedByCount = collected.entrySet()
  54. .stream()
  55. .sorted((Map.Entry.<String, Integer>comparingByValue().reversed()))
  56. .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
  57.  
  58. sortedByCount.forEach((s,u) -> System.out.println(s+": "+u));
  59.  
  60. junk.forEach((s,u) -> System.out.println(s+": "+u));
  61. break;
  62. } else if (collected.containsKey("fragments") && collected.get("fragments")>=250){
  63. System.out.println("Valanyr obtained!");
  64. collected.put("fragments",collected.get("fragments")-250);
  65.  
  66. collected.putIfAbsent("shards",0);
  67. collected.putIfAbsent("motes",0);
  68.  
  69. Map<String, Integer> sortedByCount;
  70. sortedByCount = collected.entrySet()
  71. .stream()
  72. .sorted((Map.Entry.<String, Integer>comparingByValue().reversed()))
  73. .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
  74. sortedByCount.forEach((s,u) -> System.out.println(s+": "+u));
  75.  
  76. junk.forEach((s,u) -> System.out.println(s+": "+u));
  77. break;
  78. }else if (collected.containsKey("motes") && collected.get("motes")>=250){
  79. System.out.println("Dragonwrath obtained!");
  80. collected.put("motes",collected.get("motes")-250);
  81.  
  82. collected.putIfAbsent("fragments",0);
  83. collected.putIfAbsent("shards",0);
  84.  
  85. Map<String, Integer> sortedByCount;
  86. sortedByCount = collected.entrySet()
  87. .stream()
  88. .sorted((Map.Entry.<String, Integer>comparingByValue().reversed()))
  89. .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
  90.  
  91. sortedByCount.forEach((s,u) -> System.out.println(s+": "+u));
  92.  
  93. junk.forEach((s,u) -> System.out.println(s+": "+u));
  94. break;
  95. }
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement