【JAVA】File Search Tool
来源:互联网 发布:java发送xml报文实例 编辑:程序博客网 时间:2024/06/04 19:06
File Search Tool
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
http://acm.hdu.edu.cn/showproblem.php?pid=2279
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~
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.
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".
If there is no file name that can match the pattern, print "Not match".
Sample Input
4 5thistheanist*?h*s??e**se
Sample Output
2112Not 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
- 【JAVA】File Search Tool
- hdu 2279 File Search Tool(java正则表达式使用)
- java tool
- Linux search file path
- linux file search
- Java decompile tool set
- Java Top Tool
- Java performance tool
- java key tool 命令
- .cvspass file generation to configure hudson tool
- Get apk file information with aapt tool
- excel tool: List objects / file and folders
- eclipse中ctrl+h默认打开是Java Search,怎么设置成默认打开是File Search?
- eclipse中ctrl+h默认打开是Java Search,怎么设置成默认打开是File Search?
- eclipse中ctrl+h默认打开是Java Search,怎么设置成默认打开是File Search?
- eclipse file search file name pattern集合
- linux命令温故而知新:search file
- Eclipse : Class file name must end with .class exception in Java Search
- 高效SQL语句必杀技
- 2012.4.13 360笔试总结
- 图片鼠标悬浮预览 jquery 实现
- oracle 密码更改
- winsock(一)
- 【JAVA】File Search Tool
- Windows Phone本地数据库性能最佳实践
- c#获取当前路径的方法集合
- HDU-1280 HASH
- 图片二进制互相转换C#
- Java中final、finally 和 finalize
- Windows Phone 7的XML操作详解:读取,过滤以及数据绑定
- 怎样判断ios app 第一次启动
- MPICH安装后jumpshot未安装的解决方法