/ * Title: implement a function for matching comprises positive and '*' in the expression '.'. '' Represents the ratio with any character, '*' means zero or more matching strings. * / / * Idea: using recursive method. Basic conditions: pattern string when the character string and the presence of empty. Other cases: Consider mode '× *' and the situation is not '× *' case. * / #Include <the iostream> #include <string.h> #include <algorithm> #include <the cmath> #include <stdio.h> the using namespace STD; BOOL coreMatch (STR char *, char * pattern) { // STR or in the case of the pattern available IF (STR * == '\ 0' && * pattern == '\ 0') { return to true; } ! IF (STR * = '\ 0' && * pattern == '\ 0 ') { return to false; return coreMatch(str,pattern+2); } return false; } //str和pattern均不空 if(*(pattern+1) == '*'){ if(*pattern != *str && *pattern != '.'){ bool flag = coreMatch(str,pattern+2); return flag; }else{ bool flag = (coreMatch(str,pattern+2) || coreMatch(str+1,pattern) || coreMatch(str+1,pattern+2)); return flag; } }else if(*str == *pattern || *pattern == '.' ){ return coreMatch(str+1,pattern+1); } return false; } bool match(char* str, char* pattern) { if(str == nullptr || pattern == nullptr){ return false; } return coreMatch(str,pattern); } int main(){ cout<<coreMatch("",".*"); }