Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package com.company.ExamM;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.Arrays;
  7.  
  8. public class Labb {
  9. public static void main(String[] args) {
  10. Scanner sc = new Scanner(System.in);
  11.  
  12. String[] shops = sc.nextLine().split(" ");
  13. List<String> shopLine = new ArrayList<>();
  14. int N = Integer.parseInt(sc.nextLine());
  15.  
  16. for (int i = 0; i < shops.length; i++) {
  17. shopLine.add(shops[i]);
  18. }
  19. for (int n = 1; n <= N; n++) {
  20. String[] commands = sc.nextLine().split(" ");
  21.  
  22. switch (commands[0]) {
  23. case "Include":
  24. shopLine.add(commands[1]);
  25. break;
  26.  
  27.  
  28. case "Visit":
  29. int index = Integer.parseInt(commands[2]);
  30.  
  31. if (index <= shopLine.size() && index >= 0) {
  32.  
  33. if (commands[1].equalsIgnoreCase("first")) {
  34. for (int i = 0; i < index; i++) {
  35. shopLine.remove(i);
  36. }
  37. } else if (commands[1].equalsIgnoreCase("last")) {
  38. for (int i = shopLine.size(); i > index; i--) {
  39. shopLine.remove(i);
  40. }
  41. }
  42. } else {
  43. break;
  44. }
  45.  
  46.  
  47. break;
  48. case "Prefer":
  49. int one = Integer.parseInt(commands[1]);
  50. int two = Integer.parseInt(commands[2]);
  51. String w1 = shopLine.get(one);
  52. String w2 = shopLine.get(two);
  53. shopLine.set(one, w2);
  54. shopLine.set(two, w1);
  55. break;
  56. case "Place":
  57. int index1 = Integer.parseInt(commands[2]);
  58. if (index1 + 1 < shopLine.size() && index1 >= 0) {
  59. shopLine.set(index1 + 1, commands[1]);
  60. }
  61. break;
  62. }
  63. }
  64.  
  65.  
  66. System.out.print("Shops left:");
  67. System.out.println();
  68. System.out.println(String.join(" ", shopLine));
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement