Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company.ExamM;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.Arrays;
- public class Labb {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] shops = sc.nextLine().split(" ");
- List<String> shopLine = new ArrayList<>();
- int N = Integer.parseInt(sc.nextLine());
- for (int i = 0; i < shops.length; i++) {
- shopLine.add(shops[i]);
- }
- for (int n = 1; n <= N; n++) {
- String[] commands = sc.nextLine().split(" ");
- switch (commands[0]) {
- case "Include":
- shopLine.add(commands[1]);
- break;
- case "Visit":
- int index = Integer.parseInt(commands[2]);
- if (index <= shopLine.size() && index >= 0) {
- if (commands[1].equalsIgnoreCase("first")) {
- for (int i = 0; i < index; i++) {
- shopLine.remove(i);
- }
- } else if (commands[1].equalsIgnoreCase("last")) {
- for (int i = shopLine.size(); i > index; i--) {
- shopLine.remove(i);
- }
- }
- } else {
- break;
- }
- break;
- case "Prefer":
- int one = Integer.parseInt(commands[1]);
- int two = Integer.parseInt(commands[2]);
- String w1 = shopLine.get(one);
- String w2 = shopLine.get(two);
- shopLine.set(one, w2);
- shopLine.set(two, w1);
- break;
- case "Place":
- int index1 = Integer.parseInt(commands[2]);
- if (index1 + 1 < shopLine.size() && index1 >= 0) {
- shopLine.set(index1 + 1, commands[1]);
- }
- break;
- }
- }
- System.out.print("Shops left:");
- System.out.println();
- System.out.println(String.join(" ", shopLine));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement