A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/dc/d14/wildcard__matching_8cpp_source.html below:

TheAlgorithms/C++: backtracking/wildcard_matching.cpp Source File

Go to the documentation of this file. 39

std::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]) {

73

wildcard_matching(s, p, pos1 + 1, pos2 + 1);

78 if

(p[pos2] ==

'?'

) {

80

wildcard_matching(s, p, pos1 + 1, pos2 + 1);

83 else if

(p[pos2] ==

'*'

) {

85

wildcard_matching(s, p, pos1, pos2 + 1) ||

86

wildcard_matching(s, p, pos1 + 1, pos2);

90 return dpTable

[pos1][pos2] = 0;

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.

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