GeoCitesSites.com

Problem # 1 : Wilcard matches

Recall the concept of Wild-Cards used in DOS. Two meta-characters ? and "*" are used for this purpose. To simplify the problem we will assume that the filenames are only 8 characters long (without extensions) and can only contain English alphabets A-Z (in upper case). Filenames with less than 8 characters are padded with spaces.

A "?" matches with any single character and a blank/space after a filename (the padding spaces) For example:
{ AAB AXB AYB AZB } matches with A?B
{ ABP ABQ ABR AB } match with AB?

A "*" matches with all the characters till the end of a filename. In fact it is equivalent to a wild-card
containing a sequence of "?" upto the 8th position.
For example: ABCD* is equivalent to ABCD???? and they match with
{ ABCD ABCDX ABCDEFGH}

Write a function MATCH(WILDCARD$ FILENAME$) that returns -1 (true) if the wildcard matches with the filename or 0 (false) otherwise.

Sample Output
MATCH("AB?D*" ABCDPQRS) returns -1
MATCH( A??D?" ADDDX ) returns -1
MATCH( XYZ?" XYZAB ) returns 0
MATCH( ???????" ABCDEFGH ) returns 0
MATCH("????????" ABCDEFGH ) returns -1
MATCH("ABC?*" ABC ) returns -1
MATCH("ABC*E" ABCDDD ) returns -1


Previous Problem
Return to problems at The Vault
(Back to problems at The Vault )
Next Problem