Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 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.  
  10.         List<String> listShops = Arrays.stream(scanner.nextLine().split("\\s+")).collect(Collectors.toList());
  11.         int n = Integer.parseInt(scanner.nextLine());
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             String input = scanner.nextLine();
  15.  
  16.             String[] tokens = input.split("\\s+");
  17.             String command = tokens[0];
  18.             switch (command) {
  19.                 case "Include": {
  20.                     String shop = tokens[1];
  21.                     listShops.add(shop);
  22.  
  23.  
  24.                     break;
  25.                 }
  26.                 case "Visit": {
  27.                     String firtsLast = tokens[1];
  28.                     int numberOfShop = Integer.parseInt(tokens[2]);
  29.                     if (numberOfShop <= listShops.size()){
  30.                         if (firtsLast.equals("first")) {
  31.                             listShops.remove(0);
  32.  
  33.                         } else if (firtsLast.equals("last")) {
  34.                             listShops.remove(listShops.size()-1);
  35.                         }
  36.                     }
  37.  
  38.  
  39.  
  40.                     break;
  41.                 }
  42. //                case "Prefer": {
  43. //                    int shopIndex1 = Integer.parseInt(tokens[1]);
  44. //                    int shopIndex2 = Integer.parseInt(tokens[2]);
  45. //                    if (shopIndex1 < listShops.size() && shopIndex2 < listShops.size()) {
  46. //
  47. //                        int shop1 = listShops.indexOf(shopIndex1);
  48. //
  49. //
  50. //
  51. //                    }
  52. //                    break;
  53. //                }
  54.                 case "Place": {
  55.                     String shop = tokens[1];
  56.                     int shopIndex = Integer.parseInt(tokens[2]);
  57.                     if (shopIndex + 1 < listShops.size()) {
  58.                         listShops.add(shopIndex + 1, shop);
  59.                     }
  60.                     break;
  61.                 }
  62.             }
  63.         }
  64.         System.out.println("Shops left:");
  65.         System.out.println(String.join(" ", listShops));
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement