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",&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\n");
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\n");
else
printf("NO\n"); } return 0; }


CodeForces 832B Petya and Exam的更多相关文章

  1. Codefroces 832B Petya and Exam

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

  2. codeforces 1282C. Petya and Exam (贪心)

    链接:https://codeforces.com/contest/1282/problem/C 题意:  有一个人参加考试,考试只有两种题,一种是简单题,每道题耗时固定为a:另一种是困难题,每道题耗 ...

  3. 832B Petya and Exam

    题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...

  4. E - Petya and Exam CodeForces - 832B 字典树+搜索

    E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...

  5. 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 ...

  6. 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 m ...

  7. CodeForces832-B. Petya and Exam

    补的若干年以前的题目,水题,太菜啦_(:з」∠)_    B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...

  8. B. Petya and Exam

    B. Petya and Exam 题目链接 题意 给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符, 然后给你另一串字符,这个字符串中有两个特殊的字符, ...

  9. 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 ...

随机推荐

  1. mysql中查看视图的元数据?

    需求描述: 查看视图的元数据的方法. 操作过程: 1.通过查看information_schema数据库下的views表来查看视图的定义语句 mysql> select definer,view ...

  2. python 捕捉错误,exception,traceback和sys.exc_info()比较

    import traceback,sys import requests try : requests.get('dsdsd') ##故意让他出错 except Exception,e: print ...

  3. javascript的replace方法的高级应用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. DNS原理入门

    原文链接:http://www.ruanyifeng.com/blog/2016/06/dns.html http://www.ruanyifeng.com/blog/2012/05/internet ...

  5. 【Postgres】PostgreSQL配置远程连接

    1.开启相应的防火墙端口,缺省是5432 2.访问权限配置,D:\Program Files (x86)\PostgreSQL\9.2\data/pg_hba.conf中加入如下配置,开启远程访问 3 ...

  6. Lua协程-测试2

    print("Lua 协程测试2") function testFun(n) print("into foo,n = "..n) * n) -- 挂起co协程 ...

  7. HTML 水平线

    <hr /> 标签可以在 HTML 页面中创建水平线,通常用来分隔文章中的小节 <!DOCTYPE HTML> <html> <body> <p& ...

  8. [转]logging使用

    来源:https://www.cnblogs.com/nancyzhu/p/8551506.html日志 日志是跟踪软件运行时所发生的事件的一种方法.软件开发者在代码中调用日志函数,表明发生了特定的事 ...

  9. vmp3.0.9全保护拆分解析

    https://mp.weixin.qq.com/s/WO6w_L-cYwH5KB2rilZdag 以下为了避免插件干扰,故采用x64dbg原版进行分析. 首先我通过检测到调试器的弹窗进行栈回溯,定位 ...

  10. Qt下libusb-win32的使用方法

    之前一直找不到适合WIN7下的Tiny6410的USB下载软件,正好这几天开始学习USB,所以打算自己写一个专门用于Tiny6410的WIN7下的USB下载软件. 发现了libusb这个库可以用作无驱 ...