【JAVA】File Search Tool

File Search Tool

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


Problem Description
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~

 

Input
The first line of input contains two integers N (0 < N <= 10000) and M (0 < M <=100), representing the number of file names and the number of word patterns. 
Each of the following N lines contains a file name. After those, each of the last M lines contains a name pattern. 
You can assume that the length of patterns will not exceed 6, and the length of file names will not exceed 20.
There are multiple cases in the data file, process to end of file.

 

Output
For each pattern, print a line contains the number of matched file names.
If there is no file name that can match the pattern, print "Not match".

 

Sample Input
  
  
4 5 this the an is t* ?h*s ??e* *s e
 

Sample Output
  
  
2 1 1 2 Not match


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;
        Scanner cin = new Scanner (new BufferedInputStream(System.in));
        for(;cin.hasNext();)
        {
        int a=cin.nextInt(),b=cin.nextInt();
        for(int i=0;i<a;++i)
            str[i]=cin.next();
        for(int i=0;i<b;++i)
        {
            int res=0;
            temp=cin.next();
            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);
            //通过compile()方法创建Pattern实例 
            for(int k=0;k<a;k++)
            {
 
                Matcher m=p.matcher(str[k]);
                //通过match()创建Matcher实例
                booleanrs=m.find();
                if(rs) res++;
            }
            if(res==0) System.out.println("Not match");
             else System.out.println(res);
        }
        }
    }
}



来源:http://blog.csdn.net/ACM_Ted

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值