#K16041. Wildcard Pattern Matching
Wildcard Pattern Matching
Wildcard Pattern Matching
You are given a pattern that consists of lowercase English letters together with the wildcard characters *
and ?
. The ?
character matches exactly one arbitrary character, while *
can match any sequence of characters (including an empty sequence). Your task is to determine whether a given string exactly matches the pattern.
The matching must span the entire string. For example, if the pattern is *abc
and the string is abc
, the answer is YES. However, if the pattern is a*b
and the string is cccab
, the answer is NO.
This problem tests your ability to work with string matching algorithms and regular expressions. It is a medium difficulty problem often seen in coding competitions.
inputFormat
The input is given via standard input (stdin). The first line contains an integer T, which is the number of test cases. Each test case consists of two lines:
- The first line is a pattern string containing lowercase English letters,
*
, and?
. - The second line is the string that needs to be matched against the pattern.
outputFormat
For each test case, print a single line to standard output (stdout) containing YES
if the string matches the pattern exactly, or NO
if it does not.
3
a*b
cccab
*abc
abc
a*c
abcde
NO
YES
NO
</p>