热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Comp20211218

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");
}
}
}
}

推荐阅读
author-avatar
云海雨岛
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有