P27542 [洛谷] [Language Month Competition 202406] Wildcard Matching
普及
题目描述

Problem Background

We say that two characters $a$ and $b$ are matched if and only if $a = b$ or at least one of $a$ and $b$ is the character $\texttt{?}$ (ASCII value 63). For example:
- $\texttt{x}$ and $\texttt{x}$ are matched;
- $\texttt{x}$ and $\texttt{?}$ are matched;
- $\texttt{?}$ and $\texttt{x}$ are matched;
- $\texttt{?}$ and $\texttt{?}$ are matched;
- But $\texttt{x}$ and $\texttt{y}$ are not matched.

We say that two strings $s$ and $t$ are matched if and only if $s$ and $t$ have the same length and the characters at corresponding positions are matched. For example, $\texttt{abc??z}$ and $\texttt{a?cx??}$ are matched.

Problem Description

Given two strings $s$ and $t$, define $s(l, r)$ as the substring of $s$ from the $l$-th character to the $r$-th character (where $1 \leq l \leq r \leq |s|$). For example, if $s = \texttt{luogu}$, then $s(2, 4) = \texttt{uog}$.

Now, you are asked to find all pairs $(l, r)$ such that $t$ and $s(l, r)$ are matched.

Input Format

The first line is a string $s$.
The second line is a string $t$.

Output Format

Output several lines, each containing two integers representing a pair $(l, r)$.

Output the pairs in increasing order of $l$. It can be proven that this order of output is unique.

Sample Input and Output

Sample Input #1

luogu
uog

Sample Output #1

2 4

Sample Input #2

aabbcc
b??

Sample Output #2

3 5
4 6

Sample Input #3

a?b?c?
bcc

Sample Output #3

3 5
4 6

Sample Input #4

a?b?c?
b??

Sample Output #4

2 4
3 5
4 6

Notes

Data Size and Constraints

Let $n$ denote the upper limit of the lengths of strings $s$ and $t$.

Test Case Number $n \leq$ Special Conditions
1, 2 1 None
3 300 A
4 300 B
5 300 C
6 300 None
7 1000 A
8 1000 B
9 1000 C
10 1000 None

For all test data, it is guaranteed that $1 \leq n \leq 1000$, $|t| \leq |s|$, and $s$ and $t$ contain only lowercase English letters and the character $\texttt{?}$ (ASCII value 63).

Special Conditions Table:

Code $s$ contains $\texttt{?}$ $t$ contains $\texttt{?}$
A No No
B Yes No
C No Yes
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
luogu uog
样例输出
2 4