Advertisement
Guest User

maska

a guest
Mar 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1.  public static void maska(String[] args) {
  2.         Scanner sc = new Scanner(System.in);
  3.         int tests = sc.nextInt();
  4.         sc.nextLine();
  5.         for (int test = 0; test < tests; test++) {
  6.             int n = sc.nextInt();
  7.             sc.nextLine();
  8.             String mask = sc.nextLine();
  9.             String[] parts = mask.split("\\*");
  10.             String firstPart = "";
  11.             String secondPart = "";
  12.             if (parts.length == 2) {
  13.                 firstPart = parts[0].replaceAll("[^a-z]", "");
  14.                 secondPart = parts[1].replaceAll("[^a-z]", "");
  15.             } else if (parts.length == 1) {
  16.                 firstPart = parts[0].replaceAll("[^a-z]", "");
  17.             } else if (parts.length == 0) {
  18.                 for (int i = 0; i < n; i++) {
  19.                     String line = sc.nextLine();
  20.                     if (line.length() == 0) {
  21.                         System.out.println("YES");
  22.                     } else {
  23.                         System.out.println("NO");
  24.                     }
  25.                 }
  26.                 continue;
  27.             }
  28.             for (int i = 0; i < n; i++) {
  29.                 String tempString = sc.nextLine();
  30.                 boolean result = tempString.startsWith(firstPart) && tempString.endsWith(secondPart);
  31.                 if (result) {
  32.                     System.out.println("YES");
  33.                 } else {
  34.                     System.out.println("NO");
  35.                 }
  36.             }
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement