std::vector<std::vector<int64_t>>
dpTable(1000, std::vector<int64_t>(1000, -1));
42uint32_t n = s.length();
43uint32_t m = p.length();
45 if(pos1 == n && pos2 == m) {
51 if(pos1 != n && pos2 == m) {
57 if(pos1 == n && pos2 != m) {
58 while(pos2 < m && p[pos2] ==
'*') {
66 if(
dpTable[pos1][pos2] != -1) {
71 if(s[pos1] == p[pos2]) {
73wildcard_matching(s, p, pos1 + 1, pos2 + 1);
78 if(p[pos2] ==
'?') {
80wildcard_matching(s, p, pos1 + 1, pos2 + 1);
83 else if(p[pos2] ==
'*') {
85wildcard_matching(s, p, pos1, pos2 + 1) ||
86wildcard_matching(s, p, pos1 + 1, pos2);
90 return dpTable[pos1][pos2] = 0;
104std::cout <<
"1st test ";
105std::string matching1 =
"baaabab";
106std::string pattern1 =
"*****ba*****ab";
107assert(backtracking::wildcard_matching::wildcard_matching(matching1,
110std::cout <<
"passed"<< std::endl;
113std::cout <<
"2nd test ";
114std::string matching2 =
"baaabab";
115std::string pattern2 =
"ba*****ab";
116assert(backtracking::wildcard_matching::wildcard_matching(matching2,
119std::cout <<
"passed"<< std::endl;
122std::cout <<
"3rd test ";
123std::string matching3 =
"baaabab";
124std::string pattern3 =
"ba*ab";
125assert(backtracking::wildcard_matching::wildcard_matching(matching3,
128std::cout <<
"passed"<< std::endl;
131std::cout <<
"4th test ";
132std::string matching4 =
"baaabab";
133std::string pattern4 =
"a*ab";
134assert(backtracking::wildcard_matching::wildcard_matching(matching4,
137std::cout <<
"passed"<< std::endl;
140std::cout <<
"5th test ";
141std::string matching5 =
"baaabab";
142std::string pattern5 =
"aa?ab";
143assert(backtracking::wildcard_matching::wildcard_matching(matching5,
146std::cout <<
"passed"<< std::endl;
Functions for the Wildcard Matching problem.
std::vector< std::vector< int64_t > > dpTable(1000, std::vector< int64_t >(1000, -1))
The main function implements if pattern can be matched with given string.
static void test()
Self-test implementations.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4