首页 > 试题广场 >

???

[编程题]???
  • 热度指数:892 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
有一个字符串 s ,它由小写英文字母和可能是零个或多个的字符 `?` 组成。

旺仔哥哥想将每个 `?` 改成小写英文字母,使字符串 t 成为字符串 s 的子序列(不一定连续)。

输出任何这样的可能的改写后的字符串,如果没有符合条件的字符串存在,则直接报告不可能即可。

输入描述:
第一行包含一个整数 T ( 1 \leq T \leq 10^4 ) - 测试用例数。

每个测试用例的第一行包含一个字符串 s ( 1 \leq |s| \leq 2 \cdot 10^5,且 s 仅由小写英文字母和 ```?``` 组成。

每个测试用例的第二行包含一个字符串 t ( 1 \leq |t| \leq |s| 且 t 仅由小写英文字母组成)--该字符串本应是字符串 s 的子序列。

所有测试用例中 |s| 的总和不超过 2 \cdot 10^5 ,其中 |x| 表示字符串 x 的长度。


输出描述:
对于每个测试用例,如果不存在语句中描述的字符串,则输出 "NO"(不带引号)。

否则,输出 "YES"(不带引号)。然后,输出一行--符合所有条件的字符串。

如果可能有多个答案,您可以输出其中任何一个。
示例1

输入

4
??a???e????ba
efe
cbe??????e?b???b
be
a???bf?????
deadaeefb
f???bf?efc?eeebac?
afbacea

输出

YES
efaeaaeaaaaba
YES
cbeaaaaaaeabaaab
NO
YES
fafbbfaefceeeebaca
import re
n = int(input()) for num in range(n):
    s = input()
    t = input()
    find = re.findall(r'\?+', s)
    length = sum(len(i) for i in find)
    total = 0  for i in t:
        total += s.count(i) if length >= len(t): print('YES')
        t = t + 'a' * (length - len(t))
        left = 0  right = 0  while len(s) > right: if s[right] == '?':
                s = s.replace(s[right], t[left], 1)
                left += 1  right += 1  print(s) elif s.count('?') + total >= len(t):
        left = 0  right = 0  flag = 'NO'  while len(s) > right: if s[right] == t[left]:
                left += 1  elif s[right] == '?' and left < len(t):
                s = s.replace(s[right], t[left], 1)
                left += 1  if left == len(t):
                flag = 'YES'  break  right += 1  print(flag) if flag == 'YES': if s.count('?') != 0:
                s = s.replace('?', 'a') print(s) else: print('NO')
发表于 2025-10-02 19:06:13 回复(0)