题目链接:https://codeforces.com/contest/1379/problem/A
题目描述:
对于一个字符串判断能否通过将“?”替换为字母,从而使得字符串中出现仅一次“abacaba”
解题思路:
第一次for循环枚举目标字符串的起点,第二层for循环是用来消去‘?’的,然后每次消完‘?’都check一遍字符串中是否只有一个“abacaba”。

代码:

#include <bits/stdc++.h>
using namespace std;
string a="abacaba";
bool check(string s)
{
    int cnt=0;
    for (int i=0;i<(int)s.size()-6;i++)
    cnt+=(s.substr(i,7)==a);
    return (cnt==1);
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        string s,ans="No";
        cin >> n >> s;
        for (int i=0;i<n-6;i++)
        {
            string tmp=s;
            for (int j=0;j<n;j++)
            {
                if (tmp[j]=='?')
                {
                    if (j>=i && j-i<7)
                    tmp[j]=a[j-i];
                    else
                    tmp[j]='d';
                }
            }
            if (check(tmp))
            ans="Yes\n"+tmp;
        }
        cout << ans << endl;
    }
}