首页 > 其他 > 详细

CF 1379A Acacius and String

时间:2020-07-21 12:40:21      阅读:182      评论:0      收藏:0      [点我收藏+]

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

 

CF 1379A Acacius and String

原文:https://www.cnblogs.com/JDFZ-ZZ/p/13353565.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!