Advertisement
John_IV

Untitled

Dec 13th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         Scanner sc = new Scanner(System.in);
  3.  
  4.         List<String> racers = Arrays.stream(sc.nextLine().split("\\s+")).collect(Collectors.toList());
  5.         String[] input = sc.nextLine().split(" ");
  6.  
  7.         while (!input[0].equals("end")) {
  8.             String name = input[1];
  9.             boolean contains = racers.contains(name);
  10.  
  11.             switch (input[0]) {
  12.                 case "Race":
  13.                     if (!contains) {
  14.                         racers.add(name);
  15.                     }
  16.                     break;
  17.  
  18.                 case "Accident":
  19.                     racers.remove(name);
  20.                     break;
  21.  
  22.                 case "Box":
  23.                     if (contains && !racers.get(racers.size() - 1).equals(name)) {
  24.                         int index = racers.indexOf(name);
  25.                         Collections.swap(racers, index, index + 1);
  26.                     }
  27.                     break;
  28.  
  29.                 case "Overtake":
  30.                     int position = racers.indexOf(name) - Integer.parseInt(input[2]);
  31.  
  32.                     if (contains && position >= 0) {
  33.                         racers.remove(name);
  34.                         racers.add(position, name);
  35.                     }
  36.                     break;
  37.             }
  38.  
  39.             input = sc.nextLine().split(" ");
  40.         }
  41.  
  42.         System.out.println(String.join(" ~ ", racers));
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement