Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void maska(String[] args) {
- Scanner sc = new Scanner(System.in);
- int tests = sc.nextInt();
- sc.nextLine();
- for (int test = 0; test < tests; test++) {
- int n = sc.nextInt();
- sc.nextLine();
- String mask = sc.nextLine();
- String[] parts = mask.split("\\*");
- String firstPart = "";
- String secondPart = "";
- if (parts.length == 2) {
- firstPart = parts[0].replaceAll("[^a-z]", "");
- secondPart = parts[1].replaceAll("[^a-z]", "");
- } else if (parts.length == 1) {
- firstPart = parts[0].replaceAll("[^a-z]", "");
- } else if (parts.length == 0) {
- for (int i = 0; i < n; i++) {
- String line = sc.nextLine();
- if (line.length() == 0) {
- System.out.println("YES");
- } else {
- System.out.println("NO");
- }
- }
- continue;
- }
- for (int i = 0; i < n; i++) {
- String tempString = sc.nextLine();
- boolean result = tempString.startsWith(firstPart) && tempString.endsWith(secondPart);
- if (result) {
- System.out.println("YES");
- } else {
- System.out.println("NO");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement