Created
April 22, 2014 08:33
-
-
Save swimmi/11170199 to your computer and use it in GitHub Desktop.
Searching files by queries !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
//Searching files by queries ! | |
int main() | |
{ | |
//ifstream cin("file_searching.txt"); | |
int n=0,m=0; | |
vector<string>v; | |
vector<string>vf; | |
while(cin>>n) | |
{ | |
if(!v.empty()) cout<<endl; //blank after cases except last one | |
v.clear();vf.clear(); //files and queries | |
string s; | |
for(int i=0;i<n;i++) | |
{ | |
cin>>s; | |
v.push_back(s); | |
} | |
cin>>n; | |
for(int i=0;i<n;i++) | |
{ | |
cin>>s; | |
vf.push_back(s); | |
} | |
for(int i=0;i<vf.size();i++) | |
{ | |
string bs=vf[i],as=vf[i]; //string before and after '*' | |
int x=vf[i].find("*"); //index of '*' | |
bs.erase(bs.begin()+x,bs.end()); | |
as.erase(as.begin(),as.begin()+x+1); | |
for(int j=0;j<v.size();j++) | |
{ | |
int b=v[j].find(bs);int a=v[j].find(as); //index of bs and as in the string | |
if(x==0) b=x; if(x==vf[i].length()-1) a=v[j].length(); //begin or end of the string | |
if(b==0&&a==v[j].length()-as.length()&&bs.length()<=a) //include bs and as while no crosses | |
{ | |
m++; //matched files | |
if(m>1) cout<<", "; | |
cout<<v[j]; | |
} | |
} | |
if(m==0) cout<<"FILE NOT FOUND"; | |
m=0;cout<<endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment