#K3121. Wildcard Pattern Matching
Wildcard Pattern Matching
Wildcard Pattern Matching
You are given two strings s
and p
where p
is a pattern that may contain wildcard characters. The wildcard characters are:
*
which matches any sequence of characters (including the empty sequence)?
which matches any single character
Your task is to determine if the entire string s
matches the pattern p
exactly.
The matching should cover the entire input string (not partial).
Note: Use dynamic programming or any efficient method to solve the problem as the input strings can be large.
For example, given s = "abcdef"
and p = "a*d?f"
, the output should be True
.
inputFormat
The input consists of two lines:
- The first line contains the string
s
. - The second line contains the pattern
p
which may include the wildcards*
and?
.
Both s
and p
consist only of printable ASCII characters.
outputFormat
Output a single line: True
if string s
matches pattern p
according to the described rules, otherwise output False
.
abcdef
a*d?f
True