zoukankan      html  css  js  c++  java
  • CodeForces 832B Petya and Exam

    B. Petya and Exam
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..

    There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.

    Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.

    Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.

    A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.

    The good letters are given to Petya. All the others are bad.

    Input

    The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.

    The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*" occurs in s no more than once.

    The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings.

    n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.

    It is guaranteed that the total length of all query strings is not greater than 105.

    Output

    Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.

    You can choose the case (lower or upper) for each letter arbitrary.

    Examples
    input
    ab
    a?a
    2
    aaa
    aab
    
    output
    YES
    NO
    
    input
    abc
    a?a?a*
    4
    abacaba
    abaca
    apapa
    aaaaax
    
    output
    NO
    YES
    NO
    YES
    
    
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <algorithm>
    #include <math.h>
    #include <stdio.h>
    #include <string>
    
    using namespace std;
    typedef long long int LL;
    const int maxn=1e5;
    char a[maxn+5];
    char b[maxn+5];
    int c[30];
    char s[30];
    int n;
    int main()
    {
        memset(c,0,sizeof(c));
        scanf("%s",s);
        for(int i=0;s[i];i++)
        {
            c[s[i]-'a']=1;
        }
        scanf("%s",a);
        scanf("%d
    ",&n);
        int len=strlen(a);
        for(int i=0;i<n;i++)
        {
            scanf("%s",b);
            int len2=strlen(b);
            int res=len2-len;
            if(res<-1)
            {
                printf("NO
    ");
                continue;
            }
            int j=0,k=0;
            bool ans=true;
            while(j<len||k<len2)
            {
                if(a[j]!='?'&&a[j]!='*')
                {
                    if(a[j]!=b[k])
                    {
                        ans=false;
                        break;
                    }
                    else
                    {
                        j++,k++;
                        continue;
                    }
                }
                else if(a[j]=='?')
                {
                    if(c[b[k]-'a']==1)
                    {
                        j++,k++;
                        continue;
                    }
                    else
                    {
                        ans=false;
                        break;
                    }
                }
                else
                {
                    if(res==-1)
                    {
                        j++;
                        continue;
                    }
                    else
                    {
                        for(int p=k;p<=k+res;p++)
                        {
                            if(c[b[p]-'a']==1)
                            {
                                ans=false;
                            }
    
                        }
                        if(ans==false) break;
                        else
                        {
                            j++;
                            k+=(res+1);
                            continue;
                        }
                    }
                }
    
            }
            if(ans==true)
                printf("YES
    ");
            else
                printf("NO
    ");
    
        }
    
        return 0;
    
    
    
    }


    
    
  • 相关阅读:
    SpringCloud-服务注册与实现-Eureka创建服务注册中心(附源码下载)
    SpringCloud -创建统一的依赖管理
    Mysql、Oracle、SQLServer等数据库参考文档免费分享下载
    DevExpress的图形按钮菜单栏控件WindowsUIButtonPanel的布局、使用和设置按钮的点击事件
    Winform中设置ZedGraph鼠标滚轮缩放的灵敏度以及设置滚轮缩放的方式(鼠标焦点为中心还是图形中心点)
    Winform中设置多条Y轴时新增的Y轴刻度不显示问题解决
    Winforn中设置ZedGraoh的GraphPane恢复到初始比例大小
    Winform中设置ZedGraph多条Y轴时与多条曲线一一对应
    Winform中设置ZedGraph多条Y轴时坐标轴左右显示设置
    一、关于a标签伪类中的visited不起作用问题
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228522.html
Copyright © 2011-2022 走看看