CodeForces-832B Petya and Exam

根据题意模拟匹配就好

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <string>
#include <cmath>
#include <vector>
#include <utility>
#include <set>
#include <climits>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define INF 2147483647
using namespace std;
typedef long long ll;
string good,base;
int n,i,j,k;
int main()
{
    cin>>good>>base;
    scanf("%d",&n);
    for(k=0; k<n; k++)
    {
        string s;
        cin>>s;
        if(s.size()+1<base.size())//字符串比base小一个字符以上直接continue
        {
            printf("NO\n");
            continue;
        }
        if(s.size()<base.size())//当字符串小于base
        {
            bool ok=false;
            for(i=0,j=0; i<base.size(); i++,j++)
            {
                if(base[i]!='?'&&base[i]!='*')
                {
                    if(base[i]!=s[j])
                        break;
                }
                else if(base[i]=='?')
                {
                    std::size_t found=good.find(s[j]);
                    if (found==std::string::npos)
                    {
                        break;
                    }
                }
                else if(base[i]=='*')
                {
                    j--;
                }
            }
            //cout<<i<<" "<<j<<endl;
            if(i>=base.size()&&j>=s.size())
                printf("YES\n");
            else
                printf("NO\n");
        }
        else if(s.size()==base.size())//当两字符串长度相等
        {
            for(i=0,j=0; i<base.size()&&j<s.size(); i++,j++)
            {
                if(base[i]!='?'&&base[i]!='*')
                {
                    if(base[i]!=s[j])
                        break;
                }
                else if(base[i]=='?')
                {
                    std::size_t found=good.find(s[j]);
                    if (found==std::string::npos)
                    {
                        break;
                    }
                }
                else
                {
                    std::size_t found=good.find(s[j]);
                    if (found!=std::string::npos)
                    {
                        break;
                    }
                }
            }
            if(i>=base.size()&&j>=s.size())
                printf("YES\n");
            else
                printf("NO\n");
        }
        else//当字符串大于base
        {
            int num=s.size()-base.size();
            for(i=0,j=0; i<base.size()&&j<s.size(); i++,j++)
            {
                if(base[i]!='?'&&base[i]!='*')
                {
                    if(base[i]!=s[j])
                        break;
                }
                else if(base[i]=='?')
                {
                    std::size_t found=good.find(s[j]);
                    if (found==std::string::npos)
                    {
                        break;
                    }
                }
                else
                {
                    while(1)
                    {
                        if(j>=s.size()||j-i>num)
                            break;
                        std::size_t found=good.find(s[j]);
                        if (found!=std::string::npos)
                        {
                            break;
                        }
                        j++;

                    }
                    j--;
                }
            }
            //cout<<i<<" "<<j<<endl;
            if(j>=s.size()&&i>=base.size())
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值