-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWILDCARD.cpp
More file actions
54 lines (49 loc) · 980 Bytes
/
Copy pathWILDCARD.cpp
File metadata and controls
54 lines (49 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
char pattern[101];
int N;
int checkWildCard(const string &str, int sPos, int pPos)
{
if(sPos == str.size())
{
return !pattern[pPos] || (pattern[pPos] == '*' && !pattern[pPos+1]);
}
if(!pattern[pPos]) return false;
char tok = pattern[pPos];
char match = str[sPos];
if(tok == '*')
{
if(!pattern[pPos+1]) return true;
for(;sPos < str.size(); sPos++)
{
if(checkWildCard(str, sPos, pPos+1)) return true;
}
return false;
}
return (tok == '?' || tok == match)? checkWildCard(str, sPos+1, pPos+1) : false;
}
int main()
{
int C;
scanf("%d ",&C);
for(;C--;)
{
vector<string> name;
gets(pattern);
scanf("%d ",&N);
for(int i=0;i<N;i++)
{
char temp[101];
gets(temp);
name.push_back(string(temp));
}
sort(name.begin(), name.end());
for(int i=0;i<N;i++)
if(checkWildCard(name[i],0,0))
puts(name[i].c_str());
}
}