Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class SantasList {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> kids = Arrays.stream(scanner.nextLine().split("&"))
- .collect(Collectors.toList());
- String input = scanner.nextLine();
- while (!input.equals("Finished!")) {
- String[] command = input.split(" ");
- String typeCommand = command[0];
- String name = command[1];
- // String name2 = command[2];
- if (typeCommand.contains("Bad")) {
- if (!kids.contains(name)) {
- kids.add(0, name);
- }
- }
- if (typeCommand.contains("Good")) {
- if (kids.contains(name)) {
- kids.remove(name);
- }
- } else if (typeCommand.contains("Rename")) {
- String oldName = command[1];
- int indexOld = kids.indexOf(oldName);
- String newName = command[2];
- if (kids.contains(oldName)) {
- kids.set(indexOld, newName);
- }
- } else if (typeCommand.contains("Rearrange")) {
- if (kids.contains(name)) {
- kids.remove(name);
- kids.add(name);
- }
- }
- input = scanner.nextLine();
- }
- System.out.print(String.join(", ", kids));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement