Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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 EasterShopping {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. List<String> shops = Arrays.stream(scanner.nextLine()
  10. .split("\\s+")).collect(Collectors.toList());
  11.  
  12. int n = scanner.nextInt();
  13.  
  14. while (n-- > 0) {
  15.  
  16. String input = scanner.nextLine();
  17. String[] commad = input.split(" +");
  18. String typeCommad = commad[0];
  19.  
  20. if (typeCommad.contains("Include")) {
  21. shops.add(commad[1]);
  22. } else if (typeCommad.contains("Visit")) {
  23.  
  24.  
  25. int numberShops = Integer.parseInt(commad[2]);
  26. if (shops.size() >= numberShops) {
  27.  
  28. String firstCommand = commad[1];
  29. if (firstCommand.contains("first")) {
  30. for (int i = 0; i < numberShops; i++) {
  31. int shopToRemove = shops.indexOf(shops.get(0));
  32.  
  33. shops.remove(shopToRemove);
  34. }
  35. } else if (firstCommand.contains("last")) {
  36. for (int i = 0; i < numberShops; i++) {
  37. shops.remove(shops.size() - 1);
  38. }
  39.  
  40.  
  41. }
  42.  
  43. }
  44.  
  45. } else if (typeCommad.contains("Prefer")) {
  46. int shopIndex1 = Integer.parseInt(commad[1]);
  47. int shopIndex2 = Integer.parseInt(commad[2]);
  48. String shop1 = shops.get(shopIndex1);
  49. String shop2 = shops.get(shopIndex2);
  50. shops.set(shopIndex1, shop2);
  51. shops.set(shopIndex2, shop1);
  52.  
  53.  
  54. } else if (typeCommad.contains("Place")) {
  55. int index = Integer.parseInt(commad[2]);
  56. String shopToInsert = commad[1];
  57. if (index + 1 < shops.size()) {
  58.  
  59.  
  60. shops.set(index + 1, shopToInsert);
  61.  
  62. }
  63.  
  64. }
  65.  
  66. }
  67.  
  68. System.out.println("Shops left:");
  69. for (String shop : shops) {
  70. System.out.print(shop + " ");
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement