ZOJ Problem Set - 2840 File Searching
来源:互联网 发布:实业难做 知乎 编辑:程序博客网 时间:2024/06/06 03:22
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*.docSample Output:
command.commsdos.sys, io.sys, config.sysFILE NOT FOUND
Author: ZHOU, Yuan
Source: Zhejiang University Local Contest 2007
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
string s,Left,Right;
vector<string> v,vv;
int main()
{
int n,m,i,j;
int c=0;
while(scanf("%d",&n)!=EOF)
{
if(c) cout<<endl;
c++;
v.clear();//清空
for(i=0;i<n;i++)
{
cin>>s;
v.push_back(s);//将待查询的字符串放进vector容器
}
scanf("%d",&m);
for(i=0;i<m;i++)
{
cin>>s;
int p=s.find("*");//*作为左右的分界点
Left="";//清空
Right="";
vv.clear();
for(j=0;j<p;j++)//左边的字符放进左串
Left+=s[j];
for(j=p+1;j<s.size();j++)//右边的字符放进右串
Right+=s[j];
for(j=0;j<v.size();j++)
{
if((Left.size()+Right.size()>v[j].size()))//如果待查询的字符串比左串加右串的长度还短,说明不可能,不用继续比较。剪枝。
continue;
if(Left.size()!=0)//比较左串的是否相等
{
if(v[j].find(Left)!=0)
continue;
}
if(Right.size()!=0)//反转右串后比较
{
reverse(Right.begin(),Right.end());
reverse(v[j].begin(),v[j].end());
if(v[j].find(Right)!=0)
{
reverse(Right.begin(),Right.end());
reverse(v[j].begin(),v[j].end());
continue;
}
reverse(Right.begin(),Right.end());
reverse(v[j].begin(),v[j].end());
}
vv.push_back(v[j]);//如果左右都符合,放进vector容器
}
for(j=0;j<vv.size();j++)//输出所有符合条件的string
{
cout<<vv[j];
if(j!=vv.size()-1)
cout<<", ";
else cout<<endl;
}
if(vv.size()==0)//如果vector容器为空,说明找不到。
cout<<"FILE NOT FOUND"<<endl;
}
}
return 0;
}
- ZOJ Problem Set - 2840 File Searching
- zoj 2840 File Searching
- ZOJ Problem Set - 3228 Searching the String AC自动机
- ZOJ 2840 File Searching(STL应用)
- ZOJ File Searching(字符串)
- zju 2840 File Searching
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1115
- ZOJ Problem Set - 1151
- ZOJ Problem Set - 1205
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 1029
- Java笔记十六.java中的this和super用法
- hadoop三个配置文件的参数含义说明
- android 自定义属性
- 试用GNU Gettext 开源多语组件包
- C++ Primer 笔记+习题解答(五)
- ZOJ Problem Set - 2840 File Searching
- JavaScript权威指南_56_第7章_数组_7.8-数组的方法
- Android 通过Preference启动新的Activity
- 与产生随机数相关的函数
- poj_1007 排序水题
- unity3d 4.6.1 macosx 破解(crack)
- 【002】初识C++ <二 > 保留关键字(Typedef)、构造器和析构器
- Web UI 自动化日期控件的处理
- JavaScript权威指南_57_第7章_数组_7.9-ECMAScript5中的数组方法