动态规划
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String regex = sc.nextLine().toLowerCase();
String str = sc.nextLine().toLowerCase();
boolean[][] dp = new boolean[str.length() + 1][regex.length() + 1];
dp[0][0] = true;
for (int j = 1; j < regex.length() + 1; j++) {
dp[0][j] = dp[0][j -1] && regex.charAt(j -1) == '*';
}
for (int i = 1; i < str.length() + 1; i++) {
for (int j = 1; j < regex.length() + 1; j++) {
if (regex.charAt(j -1) == '*' && ismatch(str.charAt(i -1))) {
dp[i][j] = dp[i -1][j - 1] || dp[i][j - 1] || dp[i - 1][j];
} else if (regex.charAt(j - 1) == '?' && ismatch(str.charAt(i -1))) {
dp[i][j] = dp[i - 1][j - 1];
} else if (str.charAt(i - 1) == regex.charAt(j -1)) {
dp[i][j] = dp[i - 1][j - 1];
} else {
dp[i][j] = false;
}
}
}
System.out.println(dp[str.length()][regex.length()]);
}
}
public static boolean ismatch(char a) {
return (a >= '0' && a <= '9') || (a >= 'a' && a <= 'z') ;
}
}