Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. mport java.io.Console;
  2. import java.sql.SQLOutput;
  3. import java.util.*;
  4.  
  5. public class Santas_present_factory {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. ArrayDeque<Integer>materials = new ArrayDeque<>();
  10. Arrays.stream(scanner.nextLine().split(" "))
  11. .mapToInt(Integer::parseInt)
  12. .forEach(materials::push);
  13.  
  14. ArrayDeque<Integer> magics = new ArrayDeque<>();
  15. Arrays.stream(scanner.nextLine().split(" "))
  16. .mapToInt(Integer::parseInt)
  17. .forEach(magics::offer);
  18.  
  19. LinkedHashMap<String, Integer> presents = new LinkedHashMap<>();
  20. HashMap<String, Integer> whishList = new HashMap<>();
  21. whishList.put("Doll", 150);
  22. whishList.put("Wooden train", 250);
  23. whishList.put("Teddy bear", 300);
  24. whishList.put("Bicycle", 400);
  25. int counter = 0;
  26.  
  27. while (!materials.isEmpty() && !magics.isEmpty()){
  28. int material = materials.peek();
  29. int magic = magics.peek();
  30.  
  31. int result = material*magic;
  32.  
  33.  
  34.  
  35. if (whishList.containsValue(result)) {
  36. String item = String.valueOf(presents.get(whishList));
  37. materials.pop();
  38. magics.poll();
  39. if (presents.containsKey(item)){
  40. presents.put(item, 0);
  41. counter++;
  42. }
  43. } else if (result > 0){
  44. materials.push(materials.pop()+15);
  45. magics.poll();
  46. }else if (result < 0){
  47. int sum = materials.peek()+magics.peek();
  48. materials.pop();
  49. magics.poll();
  50. magics.push(sum);
  51. } else if (result == 0){
  52. if(materials.peek() == 0){
  53. materials.pop();
  54. } else if (magics.peek()== 0){
  55. magics.poll();
  56. }
  57. }
  58. }
  59. if (presents.equals("Doll") && presents.equals("Wooden train")
  60. || presents.equals("Teddy bear") && presents.equals("Bicycle"))
  61. {
  62. System.out.println("The presents are crafted! Merry Christmas!");
  63. if (!materials.isEmpty())
  64. {
  65. System.out.println("Materials left: ");
  66. System.out.println(String.format(", ", materials));
  67. }
  68. if (!magics.isEmpty())
  69. {
  70. System.out.println("Magic left: ");
  71. System.out.println(String.format(", ", magics));
  72. }
  73.  
  74.  
  75. }
  76.  
  77. else
  78. {
  79. System.out.println("No presents this Christmas!");
  80. if (!materials.isEmpty())
  81. {
  82. System.out.println("Materials left: ");
  83. System.out.println(String.format(", ", materials));
  84. }
  85. if (!magics.isEmpty())
  86. {
  87. System.out.println("Magic left: ");
  88. System.out.println(String.format(", ", magics));
  89. }
  90.  
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement