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 scan = new Scanner(System.in);
- List<String> shops = Arrays.stream(scan.nextLine().split(" ")).collect(Collectors.toList());
- int countOfCommands = Integer.parseInt(scan.nextLine());
- String[] array;
- for (int i = 0; i < countOfCommands; i++) {
- array = scan.nextLine().split(" ");
- if (array[0].equals("Include")) {
- shops.add(array[1]);
- } else if (array[0].equals("Visit")) {
- int numberOfShopsToVisit = Integer.parseInt(array[2]);
- if (numberOfShopsToVisit <= shops.size()) {
- if (array[1].equals("first")) {
- for (int j = 0; j < numberOfShopsToVisit; j++) {
- shops.remove(0);
- }
- } else if (array[1].equals("last")) {
- for (int j = 0; j < numberOfShopsToVisit; j++) {
- shops.remove(shops.size() - 1);
- }
- }
- }
- } else if (array[0].equals("Prefer")) {
- int shopIndex1 = Integer.parseInt(array[1]);
- int shopIndex2 = Integer.parseInt(array[2]);
- String firstShop = shops.get(shopIndex1);
- String secondShop = shops.get(shopIndex2);
- shops.set(shopIndex2, firstShop);
- shops.set(shopIndex1, secondShop);
- } else if (array[0].equals("Place")) {
- String shop = array[1];
- int shopIndex = Integer.parseInt(array[2]);
- if (shopIndex + 1 <= shops.size()) {
- shops.set(shopIndex + 1, shop);
- }
- }
- }
- System.out.println("Shops left:");
- System.out.println(shops.toString().replaceAll("[\\[,\\]]", ""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement