#K62302. Wildcard Matching Problem
Wildcard Matching Problem
Wildcard Matching Problem
You are given two strings s
and p
. The pattern p
may contain special characters:
?
which matches any single character.*
which matches any sequence of characters (including the empty sequence).
Your task is to determine if the string s
matches the pattern p
completely.
This problem can be solved using dynamic programming. One common recurrence is given by:
\( dp[i][j] = \begin{cases} \text{true} & \text{if } s[0..i-1] \text{ matches } p[0..j-1] \\ \text{false} & \text{otherwise} \end{cases} \)
with the transitions considering whether the current pattern character is a literal, a ?
or a *
.
inputFormat
The input is read from standard input and consists of two lines.
- The first line contains the string
s
. - The second line contains the pattern
p
.
outputFormat
Output a single line to standard output. The output should be True
if the string s
matches the given pattern p
, and False
otherwise.
aa
a
False