题解 | 字符串通配符
字符串通配符
https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
String pattern = in.nextLine();
String target = in.nextLine();
String p_new = pattern.replace("*", "[a-zA-Z0-9]*").replace("?", "[a-zA-Z0-9]?").replace("[a-zA-Z0-9]*[a-zA-Z0-9]*[a-zA-Z0-9]*", "[a-zA-Z0-9]{0,3}").replace("[a-zA-Z0-9]*[a-zA-Z0-9]*", "[a-zA-Z0-9]{0,2}").toUpperCase();
System.out.println(target.toUpperCase().matches(p_new));
}
}
}
上海得物信息集团有限公司公司福利 1263人发布