Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 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 scan = new Scanner(System.in);
  9.  
  10. List<String> shops = Arrays.stream(scan.nextLine().split(" ")).collect(Collectors.toList());
  11.  
  12. int countOfCommands = Integer.parseInt(scan.nextLine());
  13. String[] array;
  14. for (int i = 0; i < countOfCommands; i++) {
  15. array = scan.nextLine().split(" ");
  16. if (array[0].equals("Include")) {
  17. shops.add(array[1]);
  18.  
  19. } else if (array[0].equals("Visit")) {
  20. int numberOfShopsToVisit = Integer.parseInt(array[2]);
  21. if (numberOfShopsToVisit <= shops.size()) {
  22. if (array[1].equals("first")) {
  23. for (int j = 0; j < numberOfShopsToVisit; j++) {
  24. shops.remove(0);
  25.  
  26. }
  27. } else if (array[1].equals("last")) {
  28. for (int j = 0; j < numberOfShopsToVisit; j++) {
  29. shops.remove(shops.size() - 1);
  30. }
  31. }
  32. }
  33. } else if (array[0].equals("Prefer")) {
  34. int shopIndex1 = Integer.parseInt(array[1]);
  35. int shopIndex2 = Integer.parseInt(array[2]);
  36. String firstShop = shops.get(shopIndex1);
  37. String secondShop = shops.get(shopIndex2);
  38. shops.set(shopIndex2, firstShop);
  39. shops.set(shopIndex1, secondShop);
  40. } else if (array[0].equals("Place")) {
  41. String shop = array[1];
  42. int shopIndex = Integer.parseInt(array[2]);
  43. if (shopIndex + 1 <= shops.size()) {
  44. shops.set(shopIndex + 1, shop);
  45. }
  46. }
  47. }
  48. System.out.println("Shops left:");
  49.  
  50. System.out.println(shops.toString().replaceAll("[\\[,\\]]", ""));
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement