作者:云海雨岛 | 来源:互联网 | 2023-10-12 21:19
importcom.sun.tools.javac.util.Assert;importcom.sun.tools.javac.util.Pair;importjavax.jws.
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.Pair;
import javax.jws.soap.SOAPBinding;
import javax.swing.text.html.Option;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Stream;
/*
aabaacabaac
4
a.aa*c
aa.b
a*b
b*a
*/
public class Main {
private static boolean beFound = false;
private static boolean meetStart = false;
private static void resolve(int[][] dp, int x, int y, String raw, String pat, boolean isMatched) {
int row = pat.length();
int col = raw.length();
if (x + 1
if (pat.charAt(x + 1) == '*') {
meetStart = true;
if (x + 1 == row - 1) {
System.out.println(dp[x][y] + " " + (y + 1));
beFound = true;
return;
}
if (y > 0 && dp[x + 1][y] > 0) {
return;
}
int weight = dp[x][y];
int temp = y;
while (temp
dp[x + 1][temp] = weight;
resolve(dp, x + 1, temp, raw, pat, isMatched);
if (beFound) {
return;
}
temp ++;
}
} else {
if (!isMatched) {
if (pat.charAt(x) == '*' && (pat.charAt(x + 1) == '.' || pat.charAt(x + 1) == raw.charAt(y))) {
if (y > 0 && dp[x + 1][y] > 0) {
return;
}
dp[x + 1][y] = dp[x][y];
resolve(dp, x + 1, y, raw, pat, true);
}
} else if (y + 1
if (pat.charAt(x + 1) == '.' || pat.charAt(x + 1) == raw.charAt(y + 1)) {
if (y > 0 && dp[x + 1][y + 1] > 0) {
return;
}
dp[x + 1][y + 1] = dp[x][y];
if (x + 1 == row - 1) {
System.out.println(dp[x][y] + " " + (y + 2));
beFound = true;
return;
}
resolve(dp, x + 1, y + 1, raw, pat, true);
}
}
}
}
}
public static void main(String[] args) throws ClassNotFoundException {
Scanner cn = new Scanner(System.in);
String raw = cn.nextLine();
int cnt = Integer.parseInt(cn.nextLine());
for (int i = 0; i
String pat = cn.nextLine();
int row = pat.length();
int col = raw.length();
int[][] dp = new int[row][col];
beFound = false;
meetStart = false;
for (int n = 0; n
if (pat.charAt(0) == '.' || pat.charAt(0) == raw.charAt(n)) {
dp[0][n] = n + 1;
}
if (pat.charAt(0) == '*') {
dp[0][n] = 1;
}
}
boolean matched = pat.charAt(0) != '*';
for (int m = 1; m
|
if (dp[m-1][0] == 0) {
break;
}
if (pat.charAt(m) == '*') {
dp[m][0] = dp[m-1][0];
}
if (pat.charAt(m-1) == '*' && !matched && (pat.charAt(m) == '.' || pat.charAt(m) == raw.charAt(0))) {
matched = true;
dp[m][0] = dp[m-1][0];
}
}
if (dp[row - 1][0] > 0) {
System.out.println("1 1");
continue;
}
for (int n = 0; n
if (dp[0][n] > 0) {
System.out.println("meet");
resolve(dp, 0, n, raw, pat, pat.charAt(0) != '*');
if (beFound || meetStart) {
break;
}
}
}
if (!beFound) {
System.out.println("0 0");
}
}
}
}