Advertisement
ilianrusev

Mid Exam : Last Stop

Mar 10th, 2019
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import javax.print.DocFlavor;
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Main {
  8.  
  9. public static void main(String[] args) {
  10. Scanner scanner = new Scanner(System.in);
  11.  
  12.  
  13. List<String> numbers = Arrays.stream(scanner.nextLine().split(" "))
  14. .collect(Collectors.toList());
  15.  
  16.  
  17.  
  18.  
  19. //List<String> commands = Arrays.stream(scanner.nextLine().split(" "))
  20. // .collect(Collectors.toList());
  21. String inputCommand=scanner.nextLine();
  22.  
  23. String second = "";
  24. String first = "";
  25. System.out.println();
  26.  
  27. while (!inputCommand.equals("END")) {
  28.  
  29. List<String> commands = Arrays.stream(inputCommand.split("\\s+"))
  30. .collect(Collectors.toList());
  31.  
  32.  
  33. if (commands.size() >= 2){
  34. first = commands.get(1);
  35. }
  36. if (commands.size() == 3){
  37. second = commands.get(2);
  38.  
  39. }
  40. int index = numbers.indexOf(first);
  41.  
  42. if (commands.contains("Change")) {
  43. if (numbers.contains(first)){
  44. numbers.set(index,second);
  45. }
  46. }
  47.  
  48. if (commands.contains("Hide")) {
  49. if (numbers.contains(first)) {
  50. numbers.remove(index);
  51. }
  52. }
  53.  
  54. if (commands.contains("Switch")) {
  55. if (numbers.contains(first) && numbers.contains(second)) {
  56. String safe = first;
  57. String safe2 = second;
  58. numbers.set(numbers.indexOf(second),safe);
  59. numbers.set(index,safe2);
  60.  
  61. }
  62. }
  63.  
  64. if (commands.contains("Insert")) {
  65. int firstInt = Integer.parseInt(first);
  66. if (firstInt <= numbers.size()){
  67. numbers.add(firstInt+1,second);
  68. }
  69.  
  70. }
  71.  
  72. if (commands.contains("Reverse")) {
  73. Collections.reverse(numbers);
  74.  
  75. }
  76. inputCommand=scanner.nextLine();
  77. }
  78.  
  79.  
  80. System.out.println(numbers.toString()
  81. .replace(",","")
  82. .replace("[","")
  83. .replace("]","")
  84. );
  85.  
  86. }
  87. }
Advertisement
RAW Paste Data Copied
Advertisement