Codeforces Round #425 (Div. 2)B. Petya and Exam

题目大意

给出一个字符串和多组询问,‘?’代表一个好的字符,‘*’代表一个坏的字符串(可以是空串),能否让询问和字符串相同。

题解

由于‘*’只有一个,可以知道其代表的长度,暴力判断即可。(要注意询问比字符串长的情况)。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
    char ch=getchar();int f=0;
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9')
    {f=(f<<1)+(f<<3)+ch-'0';
    ch=getchar();}
    return f;
}
char s[100006],a[35],b[100005];bool ok[55],ac;
int main()
{
    scanf("%s",a+1);
    int x=strlen(a+1);
    for(int i=1;i<=x;i++)
    ok[a[i]-'a']=1;
    scanf("%s",s+1);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='*')
        ac=1;
    }
    int t=read();
    while(t--)
    {
        scanf("%s",b+1);
        int m=strlen(b+1);
        int len=m-n+1;
        if(!ac&&n!=m)
        {
            printf("NO\n");
            continue;
        }
        else if(len<0)
        {
            printf("NO\n");
            continue;
        }
        else
        {
            int temp=0;bool ak=1;
            for(int i=1;i<=n;i++)
            {
                if(s[i]!='*'&&s[i]!='?')
                {
                    if(b[i+temp]!=s[i])
                    {
                        ak=0;
                        break;
                    }
                }
                else if(s[i]=='?')
                {
                    if(!ok[b[i+temp]-'a'])
                    {
                        ak=0;
                        break;
                    }
                }
                else
                {
                    bool acak=1;
                    for(int j=0;j<len;j++)
                    {
                        if(ok[b[i+j]-'a'])
                        {
                            acak=0;
                            break;
                        }
                    }
                    if(!acak)
                    {
                        ak=0;
                        break;
                    }
                    else
                    temp=len-1;
                }
            }
            if(ak)
            printf("YES\n");
            else printf("NO\n");
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值