Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] line = scanner.nextLine().split(" +");
- List<String> shops = new ArrayList<>();
- for (int i = 0; i < line.length; i++) {
- shops.add(line[i]);
- }
- Integer count = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < count; i++) {
- String[] input = scanner.nextLine().split(" +");
- String command = input[0];
- if (command.contains("Include")) {
- String shop = input[1];
- shops.add(shop);
- } else if (command.contains("Visit")) {
- String firstOrLAst = input[1];
- int countToRemove = Integer.parseInt(input[2]);
- if(countToRemove<=shops.size()){
- if (firstOrLAst.equals("first")) {
- for (int j = 0; j < countToRemove; j++) {
- for (int k = 0; k < shops.size(); k++) {
- if (k>= 0 && k < shops.size()) {//j<shop
- shops.remove(k);
- k--;
- break; //obhojdame spisyka
- }
- }
- }
- } else if (firstOrLAst.equals("last")) {
- for (int j = 0; j < countToRemove; j++) {
- for (int k = shops.size() - 1; k >= 0; k--) {
- if (k >= shops.size()-1 && k < shops.size()) {//k<shop
- shops.remove(k);
- break;
- }
- }
- }
- }
- }
- } else if (command.contains("Prefer")) {
- int index1 = Integer.parseInt(input[1]);
- int index2 = Integer.parseInt(input[2]);
- if (index1 >= 0 && index1 < shops.size()) {
- if (index2 >= 0 && index2 < shops.size()) {
- Collections.swap(shops, index1, index2);
- }
- }
- // System.out.println(shops);
- }else if(command.contains("Place")){
- String shop=input[1];
- int index=Integer.valueOf(input[2])+1;
- if(index>=0&&index<shops.size()){
- shops.add(index,shop);
- }
- }
- }
- System.out.println("Shops left:");
- for (String shop : shops) {
- System.out.print(shop+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement