Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class EasterGifts2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" ");
- List<String> gifts = new ArrayList<>(Arrays.asList(input));
- String command = scanner.nextLine();
- while (!command.equals("No Money")) {
- String[] com = command.split(" ");
- String differentCommand = com[0];
- if (differentCommand.equals("OutOfStock")) {
- for (String gift : gifts) {
- int index = gifts.indexOf(com[1]);
- if (index >= 0 && index <= gifts.size()) {
- gifts.set(index, "None");
- }
- }
- } else if (differentCommand.equals("Required")) {
- String requiredGift = com[1];
- int index = Integer.parseInt(com[2]);
- if (index >= 0 && index <= gifts.size()) {
- gifts.set(index, requiredGift);
- }
- } else if (differentCommand.equals("JustInCase")) {
- int index = gifts.size() - 1;
- gifts.set(index, com[1]);
- }
- command = scanner.nextLine();
- }
- for (String gift : gifts) {
- if(!gift.equals("None")){
- System.out.print(gift + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement