1. 程式人生 > 實用技巧 >CF 1379A Acacius and String

CF 1379A Acacius and String

https://codeforces.com/problemset/problem/1379/A

大水題,怎麼暴力怎麼來

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int T,n,cnt,tot,ans[105];
char s[100],t[20]={'a','b','a','c','a','b','a'},c[100];
bool tag;
inline int read()
{
    int f=1,w=0;
    char ch=0;
    while(ch<'
0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { w=(w<<1)+(w<<3)+ch-'0'; ch=getchar(); } return f*w; } void opt(char x) { if(x=='?') printf("d"); else printf(
"%c",x); } int main() { T=read(); for(;T;T--) { n=read(); tot=cnt=0; tag=false; scanf("%s",s); for(int i=0;i<n-6;i++) for(int j=0;j<7;j++) { if(s[i+j]!=t[j]&&s[i+j]!='?') break;
if(j==6) ans[++tot]=i; } for(int i=1;i<=tot;i++) { cnt=0; memcpy(c,s,sizeof(c)); for(int j=0;j<7;j++) c[ans[i]+j]=t[j]; for(int j=0;j<n-6;j++) for(int k=0;k<7;k++) { if(c[j+k]!=t[k]) break; if(k==6) cnt++; } if(cnt>1||cnt==0) continue; else if(cnt==1) { puts("Yes"); tag=true; for(int j=0;j<n;j++) opt(c[j]); printf("\n"); break; } } if(!tag) puts("No"); } return 0; }
Acacius and String