【HDU2279】File Search Tool(JAVA正则匹配)

Categories: 数据结构和算法
Tags: ,
Comments: No Comments
Published on: 2011 年 05 月 17 日

WisKey downloaded much software in winter vacation, and the disk was in a state of confusion. He wastes many times to find the file everyday. So he wants a tool to help him do this work.
The file name consists of lowercase letters.
The name pattern is a string of lowercases, '?'s and '*'s. In a pattern, a '?' matches any single lowercase, and a '*' matches none or more lowercases.
Let’s do this~

import java.io.*;
import java.util.regex.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception
		String str[]=new String[10005];
		String temp;
		//Pattern p=Pattern.compile(regEx);
		Scanner cin=new Scanner(System.in);
		int a=cin.nextInt(),b=cin.nextInt();
		for(int i=0;i<a;i++)
		for(int i=0;i<b;i++)
			int res=0;
			String ss="^";
			for(int k=0;k<temp.length();k++)
				if(temp.charAt(k)=='?') ss+='.';
				else if(temp.charAt(k)=='*') ss+=".*";
				else ss+=temp.charAt(k);
			ss +="$";
			Pattern p=Pattern.compile(ss); 
			for(int k=0;k<a;k++)
				Matcher m=p.matcher(str[k]); 
				boolean rs=m.find(); 
				if(rs) res++;
			if(res==0) System.out.println("Not match");
			else System.out.println(res);


No Comments - Leave a comment

Leave a comment

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Welcome , today is 星期四, 2019 年 02 月 21 日