-
algospot - wildcardAlgorithm/알고스팟 2020. 2. 2. 14:42123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990//algospot - wildcard#include <iostream>#include <vector>#include <algorithm>using namespace std;int N;string wc;string s;string* sarr;vector<vector<int>> cache;vector<string> ans;void init(){ans = vector<string>();cin >> wc;cin >> N;sarr = new string[N];for(int i = 0; i<N; ++i)cin >> sarr[i];}int dp(int widx, int sidx){if(widx == wc.size() - 1 && sidx == s.size() - 1)if(wc[widx] == s[sidx] || wc[widx] == '?' || wc[widx] == '*')return 1;elsereturn 0;else if(widx == wc.size() - 1)if(wc[widx] == '*')return 1;else return 0;else if(sidx == s.size() - 1)if(wc[widx] == '*')return dp(widx+1, sidx);else if(wc[widx] == s[sidx]){for(int i = widx+1; i<wc.size(); ++i)if(wc[i] != '*')return 0;return 1;}elsereturn 0;int& ret = cache[widx][sidx];if(ret != -1)return ret;ret = 0;if(wc[widx] == '?' || wc[widx] == s[sidx])ret = dp(widx+1, sidx+1);else if(wc[widx] == '*'){ret += dp(widx, sidx+1);ret += dp(widx+1, sidx+1);ret += dp(widx+1, sidx);}return ret;}void cmp(int idx){s = sarr[idx];cache = vector<vector<int>>(wc.size(), vector<int>(s.size(), -1));int flag = dp(0,0);if(flag)ans.push_back(s);}int main(){int C; cin >> C;for(int tn = 0; tn<C; ++tn){init();for(int i = 0; i<N; ++i)cmp(i);sort(ans.begin(), ans.end());cout << "\n";for(int i = 0; i<ans.size(); ++i)cout << ans[i] << "\n";cout << "\n";}}
cs https://algospot.com/judge/problem/read/WILDCARD
algospot.com :: WILDCARD
Wildcard 문제 정보 문제 와일드카드는 다양한 운영체제에서 파일 이름의 일부만으로 파일 이름을 지정하는 방법이다. 와일드카드 문자열은 일반적인 파일명과 같지만, * 나 ? 와 같은 특수 문자를 포함한다. 와일드카드 문자열을 앞에서 한 글자씩 파일명과 비교해서, 모든 글자가 일치했을 때 해당 와일드카드 문자열이 파일명과 매치된다고 하자. 단, 와일드카드 문자열에 포함된 ? 는 어떤 글자와 비교해도 일치한다고 가정하며, * 는 0 글자 이상의 어떤 문자
algospot.com
DP문제, '*' 에 몇가지 알파벳이 대응되는지 확인해주면 됩니다!
'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - lis (0) 2020.02.02 algospot - trianglepath (0) 2020.02.02 algospot - jumpgame (0) 2020.02.02 algospot - lan (0) 2020.01.31 algospot - promises (0) 2020.01.29