Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mport java.io.Console;
- import java.sql.SQLOutput;
- import java.util.*;
- public class Santas_present_factory {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayDeque<Integer>materials = new ArrayDeque<>();
- Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .forEach(materials::push);
- ArrayDeque<Integer> magics = new ArrayDeque<>();
- Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .forEach(magics::offer);
- LinkedHashMap<String, Integer> presents = new LinkedHashMap<>();
- HashMap<String, Integer> whishList = new HashMap<>();
- whishList.put("Doll", 150);
- whishList.put("Wooden train", 250);
- whishList.put("Teddy bear", 300);
- whishList.put("Bicycle", 400);
- int counter = 0;
- while (!materials.isEmpty() && !magics.isEmpty()){
- int material = materials.peek();
- int magic = magics.peek();
- int result = material*magic;
- if (whishList.containsValue(result)) {
- String item = String.valueOf(presents.get(whishList));
- materials.pop();
- magics.poll();
- if (presents.containsKey(item)){
- presents.put(item, 0);
- counter++;
- }
- } else if (result > 0){
- materials.push(materials.pop()+15);
- magics.poll();
- }else if (result < 0){
- int sum = materials.peek()+magics.peek();
- materials.pop();
- magics.poll();
- magics.push(sum);
- } else if (result == 0){
- if(materials.peek() == 0){
- materials.pop();
- } else if (magics.peek()== 0){
- magics.poll();
- }
- }
- }
- if (presents.equals("Doll") && presents.equals("Wooden train")
- || presents.equals("Teddy bear") && presents.equals("Bicycle"))
- {
- System.out.println("The presents are crafted! Merry Christmas!");
- if (!materials.isEmpty())
- {
- System.out.println("Materials left: ");
- System.out.println(String.format(", ", materials));
- }
- if (!magics.isEmpty())
- {
- System.out.println("Magic left: ");
- System.out.println(String.format(", ", magics));
- }
- }
- else
- {
- System.out.println("No presents this Christmas!");
- if (!materials.isEmpty())
- {
- System.out.println("Materials left: ");
- System.out.println(String.format(", ", materials));
- }
- if (!magics.isEmpty())
- {
- System.out.println("Magic left: ");
- System.out.println(String.format(", ", magics));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement