旺仔哥哥想将每个 `?` 改成小写英文字母,使字符串
输出任何这样的可能的改写后的字符串,如果没有符合条件的字符串存在,则直接报告不可能即可。
第一行包含一个整数(
) - 测试用例数。
每个测试用例的第一行包含一个字符串(
,且
仅由小写英文字母和 ```?``` 组成。
每个测试用例的第二行包含一个字符串(
且
仅由小写英文字母组成)--该字符串本应是字符串
的子序列。
所有测试用例中的总和不超过
,其中
表示字符串
的长度。
对于每个测试用例,如果不存在语句中描述的字符串,则输出 "NO"(不带引号)。
否则,输出 "YES"(不带引号)。然后,输出一行--符合所有条件的字符串。
如果可能有多个答案,您可以输出其中任何一个。
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')