Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class EasterShopping {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> listShops = Arrays.stream(scanner.nextLine().split("\\s+")).collect(Collectors.toList());
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < n; i++) {
- String input = scanner.nextLine();
- String[] tokens = input.split("\\s+");
- String command = tokens[0];
- switch (command) {
- case "Include": {
- String shop = tokens[1];
- listShops.add(shop);
- break;
- }
- case "Visit": {
- String firtsLast = tokens[1];
- int numberOfShop = Integer.parseInt(tokens[2]);
- if (numberOfShop <= listShops.size()){
- if (firtsLast.equals("first")) {
- listShops.remove(0);
- } else if (firtsLast.equals("last")) {
- listShops.remove(listShops.size()-1);
- }
- }
- break;
- }
- // case "Prefer": {
- // int shopIndex1 = Integer.parseInt(tokens[1]);
- // int shopIndex2 = Integer.parseInt(tokens[2]);
- // if (shopIndex1 < listShops.size() && shopIndex2 < listShops.size()) {
- //
- // int shop1 = listShops.indexOf(shopIndex1);
- //
- //
- //
- // }
- // break;
- // }
- case "Place": {
- String shop = tokens[1];
- int shopIndex = Integer.parseInt(tokens[2]);
- if (shopIndex + 1 < listShops.size()) {
- listShops.add(shopIndex + 1, shop);
- }
- break;
- }
- }
- }
- System.out.println("Shops left:");
- System.out.println(String.join(" ", listShops));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement