Codeforces Round #425 B

Petya and Exam

题意:定义n个字符(小写字母)是好的,其余小写字母都是坏的,给一个字符s串含有“?”表示“?”可以替换成任意好的字符,含有最多一个“*”表示“*”可以替换成任意长度的由坏的字符组成的字符串,给q个询问,每个询问有一个小写字母组成的字符串,询问字符串经过替换后能否与查询的串一样

思路:xjb模拟,题意真jb迷

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#define ll long long
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a) memset(a,0,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lrt (root*2)
#define rrt (root*2+1)
#define len (r-l+1)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

char s1[N],s2[N],s[N];
int n;
map<char,int> M;
int main(){
    cin>>s1+1>>s2+1;
    int l1=strlen(s1+1), l2=strlen(s2+1);
    for(int i=1; i<=l1; ++i){
        M[s1[i]]=1;
    }
    cin>>n;
    while(n--){
        cin>>s+1;
        int ls=strlen(s+1),i=1,j=0,flag=0; //cout<<ls<<endl;
        for(i=1; i<=l2; ++i){
            if(s2[i]=='*'){
                for(j=0; j<=ls-l2; ++j){ //cout<<s[j+i]<<"UUUU
";
                    if(M[s[j+i]]){
                        flag=1;
                        break;
                    }
                }
                --j;
            }
            else{
                if((s2[i]=='?' && !M[s[i+j]]) || (s2[i]!='?' && s2[i]!=s[i+j])){
                    flag=1;
                }
            }
            if(flag){
                cout<<"NO
";
                break;
            }
        }
        if(!flag && (--i+j)!=ls) cout<<"NO
";
        else if(!flag) cout<<"YES
";
    }
    return 0;
}
原文地址:https://www.cnblogs.com/max88888888/p/7241646.html