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> shops = Arrays.stream(scanner.nextLine()
- .split("\\s+")).collect(Collectors.toList());
- int n = scanner.nextInt();
- while (n-- > 0) {
- String input = scanner.nextLine();
- String[] commad = input.split(" +");
- String typeCommad = commad[0];
- if (typeCommad.contains("Include")) {
- shops.add(commad[1]);
- } else if (typeCommad.contains("Visit")) {
- int numberShops = Integer.parseInt(commad[2]);
- if (shops.size() >= numberShops) {
- String firstCommand = commad[1];
- if (firstCommand.contains("first")) {
- for (int i = 0; i < numberShops; i++) {
- int shopToRemove = shops.indexOf(shops.get(0));
- shops.remove(shopToRemove);
- }
- } else if (firstCommand.contains("last")) {
- for (int i = 0; i < numberShops; i++) {
- shops.remove(shops.size() - 1);
- }
- }
- }
- } else if (typeCommad.contains("Prefer")) {
- int shopIndex1 = Integer.parseInt(commad[1]);
- int shopIndex2 = Integer.parseInt(commad[2]);
- String shop1 = shops.get(shopIndex1);
- String shop2 = shops.get(shopIndex2);
- shops.set(shopIndex1, shop2);
- shops.set(shopIndex2, shop1);
- } else if (typeCommad.contains("Place")) {
- int index = Integer.parseInt(commad[2]);
- String shopToInsert = commad[1];
- if (index + 1 < shops.size()) {
- shops.set(index + 1, shopToInsert);
- }
- }
- }
- System.out.println("Shops left:");
- for (String shop : shops) {
- System.out.print(shop + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement