Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- List<String> racers = Arrays.stream(sc.nextLine().split("\\s+")).collect(Collectors.toList());
- String[] input = sc.nextLine().split(" ");
- while (!input[0].equals("end")) {
- String name = input[1];
- boolean contains = racers.contains(name);
- switch (input[0]) {
- case "Race":
- if (!contains) {
- racers.add(name);
- }
- break;
- case "Accident":
- racers.remove(name);
- break;
- case "Box":
- if (contains && !racers.get(racers.size() - 1).equals(name)) {
- int index = racers.indexOf(name);
- Collections.swap(racers, index, index + 1);
- }
- break;
- case "Overtake":
- int position = racers.indexOf(name) - Integer.parseInt(input[2]);
- if (contains && position >= 0) {
- racers.remove(name);
- racers.add(position, name);
- }
- break;
- }
- input = sc.nextLine().split(" ");
- }
- System.out.println(String.join(" ~ ", racers));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement