地址: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".

思路:

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

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; char gd[],sa[K],sb[K]; int main(void)
{
int n,la,lb,ok=;
scanf("%s%s%d",sb+,sa+,&n);
for(int i=;sb[i];i++) gd[sb[i]]=;
for(int i=;sa[i];i++) if(sa[i]=='*') ok=;
la=strlen(sa+);
while(n--)
{
scanf("%s",sb+);
lb=strlen(sb+);
int ff=,i,j;
if((la==lb+&&!ok)||la>lb+) ff=;
if(!ok && la<lb) ff=;
for(i=,j=;i<=la&&j<=lb&&ff;i++,j++)
if(sa[i]==sb[j]||(sa[i]=='?'&&gd[sb[j]])) ;
else if(sa[i]=='*')
{
for(int k=;k<=lb-la&&ff;k++,j++)
if(gd[sb[j]]) ff=;
j--;
}
else ff=;
if(ff) printf("YES\n");
else printf("NO\n");
}
return ;
}

Codeforces Round #425 (Div. 2) B - Petya and Exam的更多相关文章

  1. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  2. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  3. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

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

    [Link]:http://codeforces.com/contest/832/problem/B [Description] *能代替一个字符串(由坏字母组成); ?能代替单个字符(由好字母组成) ...

  5. Codeforces Round #510 (Div. 2) D. Petya and Array(树状数组)

    D. Petya and Array 题目链接:https://codeforces.com/contest/1042/problem/D 题意: 给出n个数,问一共有多少个区间,满足区间和小于t. ...

  6. Codeforces Round #425 (Div. 2)C

    题目连接:http://codeforces.com/contest/832/problem/C C. Strange Radiation time limit per test 3 seconds ...

  7. Codeforces Round #425 (Div. 2)

    A 题意:给你n根棍子,两个人每次拿m根你,你先拿,如果该谁拿的时候棍子数<m,这人就输,对手就赢,问你第一个拿的人能赢吗 代码: #include<stdio.h>#define ...

  8. Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

    Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations ...

  9. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

随机推荐

  1. AWS系列-EC2默认限制说明

    Amazon EC2 提供您可以使用的不同资源,例如实例和卷. 在您创建 AWS 账户时,AWS 会针对每个区域中的这些资源设置限制.此页面列出您在 亚太区域 (东京) 中的 EC2 服务限制. 1. ...

  2. LinCode落单的数

    easy 落单的数 查看执行结果 60% 通过 给出2*n + 1 个的数字,除当中一个数字之外其它每一个数字均出现两次.找到这个数字. 您在真实的面试中是否遇到过这个题? Yes 例子 给出 [1, ...

  3. Linux命令之乐--test

    官方文档: help test File operators: -a FILE True if file exists. -b FILE True if file is block special. ...

  4. m2014-software->Word2010发布博客文章至Cnblogs

    转自:http://www.cnblogs.com/xfiver/archive/2011/12/26/2301591.html 昨夜喝醉,今天早起梳理情绪,看下如何使用word2010直接写cnbl ...

  5. java动态代理中的invoke方法是如何被自动调用的(转)

    一.动态代理与静态代理的区别. (1)Proxy类的代码被固定下来,不会因为业务的逐渐庞大而庞大: (2)可以实现AOP编程,这是静态代理无法实现的: (3)解耦,如果用在web业务下,可以实现数据层 ...

  6. GitHub Pages站点官方宣布开始使用HTTPS

    导读 数百万人依靠GitHub Pages,将其作为他们的网站主机,除此之外,还有数百万人每天访问这些网站.为了更好地保护到GitHub Pages站点的通讯,也为了鼓励在因特网上更广泛地采用HTTP ...

  7. Vue-cli 安装使用和理解

    Vue 的 官方文档 提到 点开这个链接,跟着文档一步步直到: $ npm install -g vue-cli $ vue init webpack my-project $ cd my-proje ...

  8. 文艺青年、普通青年、2b青年到底是什么意思?

    文艺青年.普通青年.2b青年到底是什么意思? 文艺青年就是脑子里跟别人想的不一样,思维跟人家相反或者另类的人. 普通青年呢就是像你一样,普普通通的. 2B青年就是黑铅笔青年,做事比较搞怪,古怪到让你哭 ...

  9. sublimeText前端必备插件

    安装完成后的sublime text,功能单纯地就像笔记本,然而,可以下载对应的插件,使得sublime text不仅仅局限于某一单一语言的编写,此处只提及到前端方面的使用,下面是前端一般使用到的插件 ...

  10. cloud native

    什么是原生云(cloud native)应用? 原生云cloud-native应用的定义是:首先,应用系统应该与底层物理基础设施解耦.说白了,应用程序应该与操作系统等基础设施分离,不应该依赖Linux ...