Advertisement
Guest User

Last Stop

a guest
Nov 1st, 2019
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. import java.util.Arrays;
  7. import java.util.List;
  8. import java.util.Scanner;
  9.  
  10. public class LastStop {
  11. public static void main(String[] args) {
  12. Scanner scanner = new Scanner(System.in);
  13. // String [] inputNums = scanner.nextLine().split(" ");
  14. // List <Integer> numbersPainting = new ArrayList<>();
  15. //
  16. // for (int i = 0; i < inputNums.length; i++) {
  17. // numbersPainting.add(Integer.parseInt(inputNums[i]));
  18. // }
  19.  
  20. List <Integer> numbersPainting = Arrays.stream(scanner.nextLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList());
  21.  
  22. String input = scanner.nextLine();
  23.  
  24. while (!input.equals("END")) {
  25. String [] command = input.split("\\s+");
  26.  
  27. switch (command[0]) {
  28. case "Change":
  29. int firstValue = Integer.parseInt(command[1]);
  30. int changedValue = Integer.parseInt(command[2]);
  31. if (numbersPainting.contains(firstValue)) {
  32. int indexFirstValue = numbersPainting.indexOf(firstValue);
  33.  
  34. numbersPainting.set(indexFirstValue, changedValue);
  35. }
  36.  
  37. break;
  38. case "Hide":
  39. int numPaintToHide = Integer.parseInt(command[1]);
  40.  
  41. if (numbersPainting.contains(numPaintToHide)) {
  42. numbersPainting.remove(Integer.valueOf(numPaintToHide));
  43. }
  44. break;
  45. case "Switch":
  46. int firstNum = Integer.parseInt(command[1]);
  47. int secondNum = Integer.parseInt(command[2]);
  48.  
  49. if (numbersPainting.contains(firstNum) && numbersPainting.contains(secondNum)) {
  50. int indexOne = numbersPainting.indexOf(firstNum);
  51. int indexTwo = numbersPainting.indexOf(secondNum);
  52.  
  53. int valueOne = numbersPainting.get(indexOne);
  54. int valueTwo = numbersPainting.get(indexTwo);
  55.  
  56. numbersPainting.add(indexOne, valueTwo);
  57. numbersPainting.add(indexTwo, valueOne);
  58. }
  59. break;
  60. case "Insert":
  61. int index = Integer.parseInt(command[1]);
  62. int paintingNum = Integer.parseInt(command[2]);
  63.  
  64. if (index+1<numbersPainting.size()) {
  65. numbersPainting.add(index+1, paintingNum);
  66. }
  67. break;
  68.  
  69. case "Reverse":
  70. Collections.reverse(numbersPainting);
  71. break;
  72. default:
  73.  
  74. }
  75. input = scanner.nextLine();
  76. }
  77.  
  78. for (int i = 0; i < numbersPainting.size(); i++) {
  79. System.out.print(numbersPainting.get(i) + " ");
  80. // System.out.println(numbersPainting.toString().replaceAll("[\\[\\],]", ""));
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement