Last active
April 28, 2019 10:31
-
-
Save DonghoonPark12/3a9d22f87066dc1b9d8b0abe470bc573 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#include <string> | |
using namespace std; | |
//bool match(const string& w, string& s); | |
int cache[101][101]; | |
string W, S; | |
bool memMatch(int w, int s); | |
int main() { | |
int T; | |
cin>>T; | |
string W; | |
int n; //파일명 갯수 | |
for (int t = 0; t < T; t++) { | |
cin >> W; | |
cin >> n; | |
string files[50];//파일 명은 최대 50개 | |
for (int i = 0; i < n; i++) { | |
string tmp; | |
cin >> files[i]; | |
} | |
for (int i = 0; i < n; i++) { | |
if(memMatch(W, files[i]) | |
cout<<files[i]; | |
} | |
} | |
return 0; | |
} | |
// bool Match(const string& w, string& s) { | |
// int pos = 0; | |
// while (pos < s.size() && pos < w.size() && (w[pos] == '?' || w[pos] == s[pos])) { | |
// pos++; | |
// } | |
// if (pos == w.size()) | |
// return pos == s.size(); | |
// if (w[pos] == '*') {//'*'를 만나서 끊긴 경우. | |
// for (int skip = 0; pos + skip <= s.size(); skip++) { | |
// cout << w.substr(pos + 1) << endl;; | |
// cout << s.substr(pos + skip)<<endl; | |
// cout << '\n'; | |
// if (match(w.substr(pos + 1), s.substr(pos + skip))) | |
// return true; | |
// } | |
// } | |
// return false; | |
// } | |
bool memMatch(int w, int s) { | |
int &ret = cache[w][s]; | |
if (ret != -1) return ret; | |
while (s < S.size() && w < W.size() && (W[w] == '?' || W[w] == S[s])) { | |
++w; ++s; | |
} | |
if (w == W.size()) | |
return ret = (s == S.size()); | |
if(W[w] == '*') | |
for (int skip = 0; skip + s < S.size(); ++skip) { | |
if (memMatch(w + 1, s + skip)) | |
return ret = 1; | |
} | |
return ret = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment