Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7.  
  8. public class SoftUniCoursePlanning {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         List<String> input = Arrays.stream(scanner.nextLine().split(", ")).collect(Collectors.toList());
  13.         String start = "";
  14.         int count = 1;
  15.  
  16.         while (!"course start".equalsIgnoreCase(start = scanner.nextLine())) {
  17.             String[] startCommand = start.split(":");
  18.  
  19.             if (startCommand[0].equalsIgnoreCase("Add")) {
  20.                 if (!input.contains(startCommand[1])) {
  21.                     input.add(startCommand[1]);
  22.                 }
  23.             } else if (startCommand[0].equalsIgnoreCase("Insert")) {
  24.                 int index = Integer.parseInt(startCommand[2]);
  25.                 if (!input.contains(startCommand[1])) {
  26.                     input.add(index, startCommand[1]);
  27.                 }
  28.             } else if (startCommand[0].equals("Remove")) {
  29.                 if (input.contains(startCommand[1])) {
  30.                     int index = input.indexOf(startCommand[1]);
  31.                     input.remove(startCommand[1]);
  32.                     if (input.contains(startCommand[1] + "-Exercise")) {
  33.                         int exerciseIndex = input.indexOf(startCommand[1] + "-Exercise");
  34.                         if (index + 1 == exerciseIndex) {
  35.                             input.remove(startCommand[1] + "-Exercise");
  36.                         }
  37.                     }
  38.                 }
  39.             } else if (startCommand[0].equals("Swap")) {
  40.                 if (input.contains(startCommand[1]) && input.contains(startCommand[2])) {
  41.                     int firstIndex = input.indexOf(startCommand[1]);
  42.                     int secondIndex = input.indexOf(startCommand[2]);
  43.                     if (input.contains(startCommand[1] + "-Exercise")) {
  44.                         int exerciseIndex1 = input.indexOf(startCommand[1] + "-Exercise");
  45.                         if (firstIndex + 1 == exerciseIndex1) {
  46.                             input.add(secondIndex, startCommand[1]);
  47.                             input.add(firstIndex+1, startCommand[2]);
  48.                             input.remove(firstIndex+2);
  49.                             input.remove(secondIndex+1);
  50.                             input.add(secondIndex + 1, startCommand[1] + "-Exercise");
  51.                             input.remove(exerciseIndex1 + 1);
  52.                         }
  53.                     }else if (input.contains(startCommand[2] + "-Exercise")) {
  54.                         int secondIndexNow = input.indexOf(startCommand[2]);
  55.                         int exerciseIndex2 = input.indexOf(startCommand[2] + "-Exercise");
  56.                         if (secondIndex + 1 == exerciseIndex2) {
  57.                             input.add(firstIndex, startCommand[2]);
  58.                             input.add(secondIndex+2, startCommand[1]);
  59.                             input.remove(firstIndex+1);
  60.                             input.remove(secondIndex);
  61.                             input.add(firstIndex + 1, startCommand[2] + "-Exercise");
  62.                             input.remove(exerciseIndex2 + 1);
  63.                         }
  64.                     } else {
  65.                         input.add(firstIndex, startCommand[2]);
  66.                         input.set(secondIndex+1,startCommand[1]);
  67.                         input.remove(firstIndex+1);
  68.                     }
  69.  
  70.                 }
  71.             } else if (startCommand[0].equalsIgnoreCase("Exercise")) {
  72.                 if (input.contains(startCommand[1])) {
  73.                     int index = input.indexOf(startCommand[1]);
  74.                     input.add(index + 1, startCommand[1] + "-Exercise");
  75.                 } else {
  76.                     input.add(startCommand[1]);
  77.                     input.add(startCommand[1] + "-Exercise");
  78.                 }
  79.             }
  80.             if (input.contains(startCommand[1] + "-Exercise")) {
  81.                 int indexFirst = input.indexOf(startCommand[1] + "-Exercise");
  82.                 if (input.contains(startCommand[1])) {
  83.                     int index = input.indexOf(startCommand[1]);
  84.                     input.add(index + 1, startCommand[1] + "-Exercise");
  85.                     input.remove(indexFirst);
  86.                 }
  87.             }
  88.         }
  89.         for (int i = 0; i < input.size(); i++) {
  90.             System.out.println(String.join("", count + "." + input.get(i)));
  91.             count++;
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement