hdu 2279 File Search Tool(java正则表达式使用)
来源:互联网 发布:酒店网络电视解决方案 编辑:程序博客网 时间:2024/06/05 00:51
牛人博客 http://blog.pureisle.net/archives/635.html
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.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Main {public static void main(String[] args) {Scanner scanner=new Scanner(System.in);while(scanner.hasNext()){ int n=scanner.nextInt(); int m=scanner.nextInt(); String string[]=new String[n+1]; for(int i=0;i<n;i++) { string[i]=scanner.next(); } for(int i=0;i<m;i++) { String string2=scanner.next(); String ss="^"; string2=string2.replace("?", "."); string2=string2.replace("*", ".*");//.*表示0个或多个字母,因为“.”就表示一个字符 ss+=string2; ss+="$"; int count=0; Pattern pattern=Pattern.compile(ss); for(int j=0;j<n;j++) { Matcher matcher=pattern.matcher(string[j]); if(matcher.find())count++; } if(count==0)System.out.println("Not match"); else System.out.println(count); }}}}
- hdu 2279 File Search Tool(java正则表达式使用)
- 【JAVA】File Search Tool
- 正则表达式第三篇(Java中使用正则表达式)
- 正则表达式第四篇(Java中使用正则表达式)
- Java正则表达式使用
- JAVA使用正则表达式
- JAVA使用正则表达式
- java使用正则表达式
- java使用正则表达式
- Java正则表达式使用
- Java使用正则表达式
- Java正则表达式使用
- java 正则表达式使用
- 正则表达式----search
- JAVA中使用正则表达式(一)
- java中使用正则表达式(2)
- 正则表达式(二)——java中使用正则
- hdu 6170(正则表达式)
- 获得系统密码(对windows 7无效)
- 关于类的设计
- 深入了解计算机系统 家庭作业 2.68
- 如何创建一个可以保存13亿数据的数组?兼谈时间和空间之间永无休止的战争
- ibatis配置
- hdu 2279 File Search Tool(java正则表达式使用)
- eclipse配置S2SH搭建过程及错误解决
- wireshark过滤规则
- 浏览器缓存机制
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- dgesvd函数
- 需要考的证书
- ibatis源码学习3_参数和结果的映射原理
- [hadoop源码阅读][4]-org.apache.hadoop.io.compress系列1-认识解码器/编码器