39std::vector<std::vector<int64_t>>
dpTable(1000, std::vector<int64_t>(1000, -1));
42 uint32_t n = s.length();
43 uint32_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]) {
83 else if (p[pos2] ==
'*') {
104 std::cout <<
"1st test ";
105 std::string matching1 =
"baaabab";
106 std::string pattern1 =
"*****ba*****ab";
107 assert(backtracking::wildcard_matching::wildcard_matching(matching1,
110 std::cout <<
"passed" << std::endl;
113 std::cout <<
"2nd test ";
114 std::string matching2 =
"baaabab";
115 std::string pattern2 =
"ba*****ab";
116 assert(backtracking::wildcard_matching::wildcard_matching(matching2,
119 std::cout <<
"passed" << std::endl;
122 std::cout <<
"3rd test ";
123 std::string matching3 =
"baaabab";
124 std::string pattern3 =
"ba*ab";
125 assert(backtracking::wildcard_matching::wildcard_matching(matching3,
128 std::cout <<
"passed" << std::endl;
131 std::cout <<
"4th test ";
132 std::string matching4 =
"baaabab";
133 std::string pattern4 =
"a*ab";
134 assert(backtracking::wildcard_matching::wildcard_matching(matching4,
137 std::cout <<
"passed" << std::endl;
140 std::cout <<
"5th test ";
141 std::string matching5 =
"baaabab";
142 std::string pattern5 =
"aa?ab";
143 assert(backtracking::wildcard_matching::wildcard_matching(matching5,
146 std::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.