Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class SantasList {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. List<String> kids = Arrays.stream(scanner.nextLine().split("&"))
  10. .collect(Collectors.toList());
  11. String input = scanner.nextLine();
  12. while (!input.equals("Finished!")) {
  13. String[] command = input.split(" ");
  14. String typeCommand = command[0];
  15. String name = command[1];
  16. // String name2 = command[2];
  17.  
  18.  
  19. if (typeCommand.contains("Bad")) {
  20. if (!kids.contains(name)) {
  21. kids.add(0, name);
  22. }
  23. }
  24.  
  25. if (typeCommand.contains("Good")) {
  26.  
  27. if (kids.contains(name)) {
  28. kids.remove(name);
  29. }
  30.  
  31.  
  32. } else if (typeCommand.contains("Rename")) {
  33. String oldName = command[1];
  34. int indexOld = kids.indexOf(oldName);
  35. String newName = command[2];
  36. if (kids.contains(oldName)) {
  37. kids.set(indexOld, newName);
  38. }
  39.  
  40. } else if (typeCommand.contains("Rearrange")) {
  41. if (kids.contains(name)) {
  42. kids.remove(name);
  43. kids.add(name);
  44. }
  45.  
  46. }
  47.  
  48.  
  49. input = scanner.nextLine();
  50. }
  51. System.out.print(String.join(", ", kids));
  52.  
  53.  
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement