#C11659. Wildcard String Matching
Wildcard String Matching
Wildcard String Matching
Problem Description:
Given two strings s1 and s2, determine whether s1 matches the pattern s2. The pattern s2 may include the wildcard character *
, which can represent any sequence (including an empty sequence) of lowercase alphabetic characters.
Formally, let \( s1 \) be a string and \( s2 \) be a pattern. The pattern is transformed by replacing every occurrence of \( * \) with the regex .*
. The two strings match if and only if the entire string s1 matches the regular expression derived from s2 (i.e., from the start to end of the string).
For example:
- If s1 = "abac" and s2 = "a*c", then the output is
True
. - If s1 = "abc" and s2 = "a*d", then the output is
False
.
inputFormat
Input Format:
The input is provided via standard input (stdin) and consists of two lines:
- The first line contains the string s1.
- The second line contains the pattern string s2, which may include the wildcard character
*
.
Both strings consist only of lowercase alphabetic characters.
outputFormat
Output Format:
Output a single line via standard output (stdout) containing either True
if s1 matches the pattern s2, or False
otherwise.
abac
a*c
True
</p>