drago68

Untitled

Oct 30th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Collectors;
  8.  
  9. public class TheFinalQuest {
  10.  
  11. public static void main(String[] args) {
  12. Scanner scanner = new Scanner(System.in);
  13.  
  14. List<String> inputInformation = Arrays.stream(scanner.nextLine().split("\\s+")).collect(Collectors.toList());
  15.  
  16. String command = scanner.nextLine();
  17.  
  18. while (!command.equals("Stop")) {
  19. List<String> enteredCommand = Arrays.stream(command.split("\\s+")).collect(Collectors.toList());
  20. String action = enteredCommand.get(0);
  21. switch (action) {
  22. case "Delete":
  23. int a = (Integer.parseInt(enteredCommand.get(1)) + 1);
  24. if (a < inputInformation.size()) {
  25. inputInformation.remove(a);
  26. }
  27. break;
  28. case "Swap":
  29. boolean wordOne = false;
  30. boolean wordTwo = false;
  31. for (int i = 0; i < inputInformation.size(); i++) {
  32. if (inputInformation.get(i).contains(enteredCommand.get(1))) {
  33. wordOne = true;
  34. }
  35. if (inputInformation.get(i).contains(enteredCommand.get(2))) {
  36. wordTwo = true;
  37. }
  38. if (wordOne && wordTwo) {
  39. int b = inputInformation.indexOf(enteredCommand.get(2));
  40. int c = inputInformation.indexOf(enteredCommand.get(1));
  41. inputInformation.set(c, enteredCommand.get(2));
  42. inputInformation.set(b, enteredCommand.get(1));
  43. break;
  44. }
  45. }
  46. break;
  47. case "Put":
  48. if (Integer.parseInt(enteredCommand.get(2)) > 0 && Integer.parseInt(enteredCommand.get(2)) < inputInformation.size()) {
  49. inputInformation.add((Integer.parseInt(enteredCommand.get(2)) - 1), enteredCommand.get(1));
  50. }
  51. break;
  52. case "Sort":
  53. Collections.reverse(inputInformation);
  54. break;
  55. case "Replace":
  56. boolean isHere = false;
  57. for (int i = 0; i < inputInformation.size(); i++) {
  58. if (enteredCommand.get(2).contains(inputInformation.get(i))) {
  59. isHere = true;
  60. }
  61. if (isHere) {
  62. int d = inputInformation.indexOf(enteredCommand.get(2));
  63. inputInformation.set(d, enteredCommand.get(1));
  64. break;
  65. }
  66.  
  67. }
  68. break;
  69. }
  70.  
  71. command = scanner.nextLine();
  72. }
  73.  
  74. for (String word : inputInformation) {
  75. System.out.print(word + " ");
  76.  
  77. }
  78. }
  79. }
Add Comment
Please, Sign In to add comment