File indexing completed on 2026-04-09 07:49:13
0001
0002
0003 #include <cassert>
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 bool match(const char* s, const char* q)
0023 {
0024 if (*q == '\0' && *s == '\0') return true;
0025
0026 if (*q == '*' && *(q+1) != '\0' && *s == '\0') return false;
0027
0028 if (*q == '$' && *(q+1) == '\0' && *s == '\0' ) return true ;
0029
0030 if (*q == '?' || *q == *s) return match(s+1, q+1);
0031
0032 if (*q == '*') return match(s, q+1) || match(s+1, q);
0033
0034 return false;
0035 }
0036
0037 int main()
0038 {
0039 assert( match("hello", "hello" ));
0040 assert( match("hello", "he*llo" ));
0041 assert( match("hello", "hello*" ));
0042 assert( match("hello", "hell*" ));
0043 assert( match("hello", "hell?" ));
0044 assert( match("hello", "?????" ));
0045 assert( match("hello", "?ell?" ));
0046 assert( match("hello", "he?lo" ));
0047 assert( match("hello", "he*" ));
0048 assert( match("hello", "he*lo" ));
0049
0050 assert(!match("hello", "????" ));
0051
0052 assert( match("he*lo", "he*lo" ));
0053 assert( match("he*lo", "he*lo" ));
0054
0055 assert( match("hello", "hello$")) ;
0056 assert( !match("helloworld", "hello$")) ;
0057
0058 }
0059