zoukankan      html  css  js  c++  java
  • Codeforces Round #425 (Div. 2) B

    地址:http://codeforces.com/contest/832/problem/B

    题目:

    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
    Note

    In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.

    Explanation of the second example.

    • The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.
    • The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.
    • The third query: "NO", because characters "?" can't be replaced with bad letters.
    • The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".

     思路:

      暴力匹配,但是这题细节多。。。。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define MP make_pair
     6 #define PB push_back
     7 typedef long long LL;
     8 typedef pair<int,int> PII;
     9 const double eps=1e-8;
    10 const double pi=acos(-1.0);
    11 const int K=1e6+7;
    12 const int mod=1e9+7;
    13 
    14 char gd[300],sa[K],sb[K];
    15 
    16 int main(void)
    17 {
    18     int n,la,lb,ok=0;
    19     scanf("%s%s%d",sb+1,sa+1,&n);
    20     for(int i=1;sb[i];i++)  gd[sb[i]]=1;
    21     for(int i=1;sa[i];i++) if(sa[i]=='*') ok=1;
    22     la=strlen(sa+1);
    23     while(n--)
    24     {
    25         scanf("%s",sb+1);
    26         lb=strlen(sb+1);
    27         int ff=1,i,j;
    28         if((la==lb+1&&!ok)||la>lb+1) ff=0;
    29         if(!ok && la<lb) ff=0;
    30         for(i=1,j=1;i<=la&&j<=lb&&ff;i++,j++)
    31         if(sa[i]==sb[j]||(sa[i]=='?'&&gd[sb[j]]))  ;
    32         else if(sa[i]=='*')
    33         {
    34             for(int k=0;k<=lb-la&&ff;k++,j++)
    35             if(gd[sb[j]]) ff=0;
    36             j--;
    37         }
    38         else ff=0;
    39         if(ff) printf("YES
    ");
    40         else printf("NO
    ");
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    Vue学习之webpack中使用vue(十七)
    Vue学习之Babel配置(十六)
    Vue学习之webpack调用第三方loader(十五)
    JAVA基础之设置随机成语验证码
    JAVA基础之HttpServletResponse响应
    Vue学习之npm常用命令及参数小结(十四)
    EXCEL 查找某个字符在字符串中最后一次出现的位置
    SQLSERVER存储过程基本语法
    SQL SERVER 字符串函数 STRING_SPLIT()
    SQL SERVER 字符串函数 PATINDEX()
  • 原文地址:https://www.cnblogs.com/weeping/p/7231935.html
Copyright © 2011-2022 走看看