这题就是暴力。暴力一定要有耐心,绝对不能慌。暴力不出来,换个方法暴力,还暴力不出来,说明基础不劳2333
源码:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string ss = "abacaba";
int main(){
int t;
cin >> t;
while(t--){
int m;
cin >> m;
string s;
cin >> s;
int f = 0;
int flag = 0;
for(int i = 0;i<m-6;i++){
flag = 0;
string t = s.substr(i,7);
for(int j = 0;j<7;j++){
if(t[j] == '?') continue;
if(t[j] != ss[j]){
flag = 1;
break;
}
}
if(!flag){
string s1 = s;
for(int j = 0;j<7;j++){
s1[i+j] = ss[j];
}
for(int j = 0;j<m;j++){
if(s1[j] == '?') s1[j] = 'd';
}
int ans = 0;
for(int j = 0;j<m-6;j++){
t = s1.substr(j,7);
if(t == ss) ans++;
}
if(ans == 1){
cout << "Yes" << endl;
cout << s1 << endl;
f = 1;
break;
}
}
}
if(!f) cout << "No" << endl;
}
return 0;
}