Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" +");
- List<String> gifts = new ArrayList<>();
- for (int i = 0; i < input.length; i++) {
- gifts.add(input[i]);
- }
- String command = scanner.nextLine();
- while (!command.equals("No Money")) {
- String[] tokens = command.split(" +");
- if (command.contains("OutOfStock")) {
- for (int i = 0; i < gifts.size(); i++) {
- String currentGift = gifts.get(i);
- String giftToNone = tokens[1];
- if (currentGift.equals(giftToNone)) {
- gifts.set(i,"None");
- }
- }
- } else if (command.contains("Required")) {
- for (int i = 0; i < gifts.size(); i++) {
- String currentGift = gifts.get(i);
- String giftToReplaceWith = tokens[1];
- int index = Integer.valueOf(tokens[2]);
- if (index >= 0 && index < gifts.size()) {
- currentGift = gifts.set(index, giftToReplaceWith);
- }
- }
- } else if (command.contains("JustInCase")) {//firdt second third third second first
- for (int i = 0; i < gifts.size(); i++) {
- String giftToAdd = tokens[1];
- String currentGift = gifts.get(i);
- String lastGift = gifts.get(gifts.size() - 1);
- gifts.remove(lastGift);
- gifts.add(giftToAdd);
- }
- }
- command = scanner.nextLine();
- }
- for (int i = 0; i < gifts.size(); i++) {
- String currentGift=gifts.get(i);
- if(!currentGift.equals("None")){
- System.out.print(gifts.get(i)+" ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement