Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. Map<String, Integer> junk = new TreeMap<>();
  11.  
  12. Map<String, Integer> keyMaterial = new LinkedHashMap<>();
  13.  
  14. keyMaterial.put("motes", 0);
  15. keyMaterial.put("fragments", 0);
  16. keyMaterial.put("shards", 0);
  17.  
  18. int shardsCount = 0;
  19. int motesCount = 0;
  20. int fragmentCount = 0;
  21. boolean isAvailable = false;
  22. while (!isAvailable) {
  23. String[] tokens = sc.nextLine().split(" ");
  24. for (int i = 0; i < tokens.length; i += 2) {
  25. int quantity = Integer.parseInt(tokens[i]);
  26. String material = tokens[i + 1].toLowerCase();
  27.  
  28. if (keyMaterial.containsKey(material)) {
  29. int value = keyMaterial.get(material) + quantity;
  30. keyMaterial.put(material, value);
  31. if (material.equals("motes")) {
  32. motesCount = keyMaterial.get("motes");
  33. if (motesCount >= 250) {
  34. isAvailable = true;
  35. keyMaterial.put("motes", motesCount-250);
  36. break;
  37. }
  38. }
  39. if (material.equals("fragments")) {
  40. fragmentCount = keyMaterial.get("fragments");
  41. if (fragmentCount >= 250) {
  42. isAvailable = true;
  43. keyMaterial.put("fragments", fragmentCount-250);
  44. break;
  45. }
  46. }
  47. if (material.equals("shards")){
  48. shardsCount = keyMaterial.get("shards");
  49. if(shardsCount >= 250){
  50. isAvailable = true;
  51. keyMaterial.put("shards", shardsCount-250);
  52. break;
  53. }
  54. }
  55.  
  56. } else {
  57. if (!junk.containsKey(material)) {
  58. junk.put(material, quantity);
  59. } else {
  60. junk.put(material, junk.get(material) + quantity);
  61. }
  62. }
  63.  
  64. }
  65. }
  66. String itemName = null;
  67. if(motesCount >= 250){
  68. itemName = "Dragonwrath";
  69. }else if(shardsCount >= 250){
  70. itemName = "Shadowmourne";
  71. }else if(fragmentCount >= 250){
  72. itemName = "Valanyr";
  73. }
  74.  
  75. System.out.printf("%s obtained!%n",itemName);
  76.  
  77. keyMaterial.entrySet().stream().sorted((f, s) -> {
  78.  
  79. return s.getValue().compareTo(f.getValue());
  80. }).forEach(entry ->{
  81. System.out.println(entry.getKey() + ": " + (entry.getValue()));
  82. });
  83.  
  84. for (Map.Entry<String, Integer> junkEntry : junk.entrySet()) {
  85. System.out.printf("%s: %d%n",junkEntry.getKey(), junkEntry.getValue());
  86. }
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement