bihan_c
1
Can anyone spot the problem here? Its failing on test case 2 upon submission
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
string pat = "abacaba";
int flag = 0, cnt = 0;
for (int i = 0; i < n - pat.length() + 1; i++) {
if (s.substr(i, 7) == pat) cnt++;
}
if (cnt > 1)
cout << "No\n";
else if (cnt == 1) {
for (int i = 0; i < n; i++) {
if (s[i] == '?') s[i] = 'd';
}
cout << "Yes\n" << s << endl;
} else if (cnt == 0) {
for (int i = 0; i < n - pat.length() + 1; i++) {
if (flag == 1) break;
for (int j = 0; j < i + pat.length(); j++) {
if (s[i + j] != pat[j] && s[i + j] != '?') break;
if (s[i + j] == '?') s[i + j] = pat[j];
if (j == pat.length() - 1) {
cnt++, flag = 1;
break;
}
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '?') s[i] = 'd';
}
if (cnt == 1 && flag == 1)
cout << "Yes\n" << s << endl;
else
cout << "No\n";
}
}
return 0;
}
You can view test details to find out the exact test.
1 Like
Solved the problem…needed to change a few things