Solution of ZOJ 2840 File Search
来源:互联网 发布:最好网络质量测试工具 编辑:程序博客网 时间:2024/05/19 00:40
Have you ever used file searching tools provided by an operating system? For example, in DOS, if you type "dir *.exe", the OS will list all executable files with extension "exe" in the current directory. These days, you are so mad with the crappy operating system you are using and you decide to write an OS of your own. Of course, you want to implement file searching functionality in your OS.
Input:
The input contains several test cases. Consecutive test cases are separated by a blank line.
Each test case begins with an integer N (1 <= N < =100), the number of files in the current directory. Then N lines follow, each line has one string consisting of lowercase letters ('a'..'z') and the dot ('.') only, which is the name of a file. Then there is an integer M (1 <= M <= 20), the number of queries. M lines follow, each has one query string consisting of lowercase letters, the dot and the star ('*') character only. Note that the star character is the "universal matching character" which is used to represent zero or numbers of characters that are uncertain. In the beginning, you just want to write a simple version of file searching, so every string contains no more than 64 characters and there is one and only one star character in the query string.
Process to the End Of File (EOF).
Output:
For each test case, generate one line for the results of each query. Separate file names in the result by a comma (',') and a blank (' ') character. The file names in the result of one query should be listed according to the order they appear in the input. If there is no matching file, output "FILE NOT FOUND" (without the quotation) instead.
Separate two consecutive test cases with a blank line, but Do NOT output an extra blank line after the last one.
Sample Input:
4command.commsdos.sysio.sysconfig.sys2com*.com*.sys3a.txtb.txtc.txt1*.doc
Sample Output:
command.commsdos.sys, io.sys, config.sysFILE NOT FOUND
Source: Zhejiang University Local Contest 2007
思路分析:题目限定查询字符串中最多只含一个'*',因此可以星号为分隔符将查询字符串分为前缀字符串和后缀字符串两部分,然后分别在字符串列表中查询其是否存在。需要留意查询字符串中不含*的情形,可利用前后缀子串长度之和与查询字符串长度的关系来判定。下面给出我的实现代码,这里用到的技巧是不事先查询星号是否存在,避免字符串的重复扫描。
关键模块:查询字符串与给定字符串是否匹配
- Solution of ZOJ 2840 File Search
- Solution of ZOJ 2420 Calendar
- Solution of ZOJ 1797 Least Common Multiplier
- Solution of ZOJ 2857 Image Transformation
- Solution of ZOJ 2850 Beautiful Meadow
- Solution of ZOJ 1188 DNA Sorting
- Solution of ZOJ 1949 Error Correcting
- Solution of ZOJ 1205 Martian Addition
- Solution of ZOJ 2748 Free Kick
- Solution of ZOJ 2109 FatMouse' Trade
- Solution of ZOJ 2679 Old Bill
- Solution of ZOJ 1067 Color Me Less
- Solution of ZOJ 1078 Palindrome Number
- Solution of ZOJ 2095 Divisor Summation (Online Version)
- solution Of Pat 1099. Build A Binary Search Tree (30)
- solution of overlap and non input data in .txt file
- Failed to detect version of solution/project file
- zoj 2840 File Searching
- What's the difference between Heap and Stack
- case convert
- 请写一个程序,随机打印“0”、“1”、“2”,但保证“0”、“1”、“2”出现的概率是可配置的,例如2:1:3。
- java Date学习总结
- 行的上下移动(包括物理移动和数据库的移动)
- Solution of ZOJ 2840 File Search
- freemark建立自定义标记宏 <@
- 解释PLMN,CELLID,LAC
- 微软面试题001-二叉树转化为链表
- 无意义-wd5
- 使用Time类遍历一学期的所有天
- 常用MFC和API函数
- 内网上线灰鸽子详细教程
- oracle 完全卸载