SHARE
TWEET

Last Stop

elvirynwa Mar 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Lists {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         List<String> paintings = Arrays.stream(scanner.nextLine().split(" ")).collect(Collectors.toList());
  12. //115 115 101 114 73 111 116 75
  13.         String input = "";
  14.  
  15.         while (!"END".equals(input = scanner.nextLine())) {
  16.             String[] data = input.split(" ");
  17.             String command = data[0];
  18.  
  19.             switch (command) {
  20.  
  21.                 case "Change":
  22.                     String paintingNumber = data[1];
  23.                     String changedNumber = data[2];
  24.  
  25.                     if (paintings.contains(paintingNumber)) {
  26.                         paintings.set(paintings.indexOf(paintingNumber), changedNumber);
  27.                     }
  28.                     break;
  29.  
  30.                 case "Hide":
  31.                     String hideNumber = data[1];
  32.  
  33.                     paintings.remove(hideNumber);
  34.                     break;
  35.  
  36.                 case "Switch":
  37.                     String firstNum = data[1];
  38.                     String secondNum = data[2];
  39.  
  40.                     if (paintings.contains(firstNum) && paintings.contains(secondNum)) {
  41.  
  42.                         if (paintings.indexOf(firstNum) > paintings.indexOf(secondNum)) {
  43.  
  44.                             paintings.add(paintings.indexOf(firstNum), secondNum);
  45.                             paintings.remove(firstNum);
  46.  
  47.                             paintings.add(paintings.indexOf(secondNum), firstNum);
  48.                             paintings.remove(secondNum);
  49.                         }else {
  50.                             paintings.add(paintings.indexOf(secondNum), firstNum);
  51.                             paintings.remove(secondNum);
  52.  
  53.                             paintings.add(paintings.indexOf(firstNum), secondNum);
  54.                             paintings.remove(firstNum);
  55.                         }
  56.  
  57.  
  58.                     }
  59.  
  60.                     break;
  61.  
  62.                 case "Insert":
  63.                     int index = Integer.parseInt(data[1]);
  64.                     String insertElement = data[2];
  65.  
  66.                     if (index >= 0 && index < paintings.size()) {
  67.                         paintings.add(index + 1, insertElement);
  68.                     }
  69.                     break;
  70.  
  71.                 case "Reverse":
  72.  
  73.                     Collections.reverse(paintings);
  74.                     break;
  75.             }
  76.         }
  77.         System.out.println(paintings.toString().replaceAll("[\\[\\],]", ""));
  78.     }
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top