地址: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 ;
}

最新文章

  1. canvas的默认尺寸
  2. Eclipse 和 HSQLDB: 将关系数据库服务器嵌入到 Eclipse 中,第 2 部分
  3. JAVA内省(Introspector)
  4. Perl 小知识之多行匹配
  5. Java安全之对称加密、非对称加密、数字签名
  6. JAVA读取本地配置文件实例
  7. servlet context 和 servlet config
  8. JavaScript的5中基本数据类型
  9. 自定义BaseServlet利用反射
  10. 史上最全的springboot导出pdf文件
  11. SQL Data Discovery and Classification
  12. vue上线后,背景图片路径错误
  13. 解决AJAX session跨域失效
  14. python用win32pdh模块查看进程信息
  15. day2_抓包-抓包工具Charles
  16. 使用Maven根据WSDL生成生成Java代码
  17. 2019/3/26 wen 数组
  18. github不能访问、加载css、js解决办法
  19. linux下安装vsftp(二)
  20. ppt正文排版

热门文章

  1. XML基础知识--&gt;Spring配置
  2. 上传Docker镜像到阿里云
  3. iOS开发之 -- bundle程序束的制造
  4. Ubuntu执行su后输入密码结果认证失败--解决办法:sudo passwd修改命令
  5. linux安装yaf(ubuntu教程)
  6. 一个网络设备的常见功能--连通性检查SSRF漏洞--被黑客利用当做扫描器
  7. NIO概览
  8. 日期选择时两个日期之间的动态控制--My97datepicker日期选择控件
  9. Python全栈day10(运算符)
  10. Code Forces 645A Amity Assessment