欢迎访问我的CCF认证解题目录
题目描述
思路过程
这题直接使用正则表达式,如果是0就设置为忽略大小写模式,直接进行匹配输出即可
代码
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.next();
int type = in.nextInt(), n = in.nextInt();
Pattern p; Matcher m;
if ( type == 0 ) {
p = Pattern.compile(str, Pattern.CASE_INSENSITIVE);//忽略大小写
} else p = Pattern.compile(str);
while ( n-- != 0 ) {
String text = in.next();
m = p.matcher(text);
if ( m.find() ) {//匹配成功
System.out.println(text);
}
}
}
}
不会正则?戳这里:字符串处理