CF1379A.Acacius and String
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Acacius is studying strings theory. Today he came with the following problem.
You are given a string s of length n consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?
Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".
Occurrence of a string t of length m in the string s of length n as a substring is a index i (1≤i≤n−m+1) such that string s[i..i+m−1] consisting of m consecutive symbols of s starting from i-th equals to string t. For example string "ababa" has two occurrences of a string "aba" as a substring with i=1 and i=3, but there are no occurrences of a string "aba" in the string "acba" as a substring.
Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.
阿卡修斯正在学习字符串理论。今天他提出了以下问题。
给你一个长度为 n 的字符串 s,它由小写英文字母和问号组成。是否可能将所有问号替换为小写英文字母,使得字符串 "abacaba" 在最终得到的字符串中恰好作为子串出现一次?
每个问号必须被恰好替换为一个小写英文字母。例如,字符串 "a?b?c" 可以被转换为 "aabbc" 和 "azbzc",但不能被转换为 "aabc"、"a?bbc" 或 "babbc"。
字符串 t(长度为 m)在字符串 s(长度为 n)中作为子串的出现,是指一个下标 i(满足 1≤i≤n−m+1),使得由 s 中从第 i 个字符开始的 m 个连续字符构成的子串 s[i..i+m−1] 恰好等于字符串 t。例如,字符串 "ababa" 中字符串 "aba" 作为子串出现了两次(对应 i=1 和 i=3),而字符串 "acba" 中则不存在 "aba" 作为子串的出现。
请帮助阿卡修斯判断:是否可能将所有问号替换为小写英文字母,使得字符串 "abacaba" 在最终字符串中恰好作为子串出现一次。
输入格式
First line of input contains an integer T (1≤T≤5000), number of test cases. T pairs of lines with test case descriptions follow.
The first line of a test case description contains a single integer n (7≤n≤50), length of a string s.
The second line of a test case description contains string s of length n consisting of lowercase English letters and question marks.
输入的第一行包含一个整数 T(1≤T≤5000),表示测试用例的数量。随后是 T 对行,每对行描述一个测试用例。
每个测试用例描述的第一行包含一个整数 n(7≤n≤50),表示字符串 s 的长度。
每个测试用例描述的第二行包含一个长度为 n 的字符串 s,该字符串由小写英文字母和问号组成。
输出格式
For each test case output an answer for it.
In case if there is no way to replace question marks in string s with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No".
Otherwise output "Yes" and in the next line output a resulting string consisting of n lowercase English letters. If there are multiple possible strings, output any.
You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).
对每个测试用例输出对应的答案。
如果无法将字符串 s 中的问号(?)替换为小写英文字母,使得最终字符串中恰好包含一个子串 "abacaba",则输出 "No"。
否则,输出 "Yes",并在下一行输出一个由 n 个小写英文字母组成的字符串。若存在多种可能的字符串,输出任意一种即可。
你可以在 "Yes" 和 "No" 中以任意大小写形式输出每个字母(例如,yEs、yes、Yes 和 YES 均被视为正确答案)。
输入输出样例
输入#1
6 7 abacaba 7 ??????? 11 aba?abacaba 11 abacaba?aba 15 asdf???f???qwer 11 abacabacaba
输出#1
Yes abacaba Yes abacaba Yes abadabacaba Yes abacabadaba No No
说明/提示
In first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.
In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.
In sixth example there are two occurrences of a string "abacaba" as a substring.
在第一个例子中,字符串 “abacaba” 作为子串在字符串 “abacaba” 中恰好出现一次。
在第二个例子中,七个问号可以被替换为任意七个小写英文字母,特别地,也可以替换为 “abacaba”。
在第六个例子中,字符串 “abacaba” 作为子串出现了两次。
输入解题思路,AI测评打分。不知道怎么写?