欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

cf 1379A

程序员文章站 2022-08-18 13:13:45
题目https://codeforces.ml/contest/1379晚安代码#include#include#include#include#include#include#include#include#include#inclu...

题目

https://codeforces.ml/contest/1379

晚安

代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
int a[1000010];	string s1="abacaba";
bool check(string &s){
	int cnt=0;
	//cout<<v<<endl;
	for(int i=0;i+7<=s.size();i++){
		if(s1==s.substr(i,7)) cnt++;
	//	cout<<s.substr(i,7)<<" "<<cnt<<endl;
	}
	return cnt==1;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		bool flag=0,flag2=0;
		for(int i=0;i+7<=s.size();i++){
			string ss=s;
			int k=i;
			bool flag1=0;
			//cout<<i<<endl;
			for(int j=0;j<s1.size();j++){
				if(s1[j]==s[k]||s[k]=='?') ss[k]=s1[j],k++;
				else{
					flag1=1;
					break;
				}
			}
		//	cout<<s<<endl;
			if(!flag1&&(check(ss))){
				for(int j=0;j<n;j++){
					if(ss[j]=='?') ss[j]='z';
				}
				cout<<"Yes"<<endl;
				flag2=1;
				cout<<ss<<endl;
				break;}
			}
		if(!flag2) cout<<"No"<<endl;
		}  
    return 0;
}

本文地址:https://blog.csdn.net/kosf_/article/details/107552193