地址: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. Loadrunner_http长连接设置

    最近协助同事解决了几个问题,也对loadrunner的一些设置加深了理解,关键是更加知其所以然. ljonathan http://www.51testing.com/html/48/202848-2 ...

  2. [转]ODBC编程指南

    DM4 ODBC编程指南本章结合DM4数据库的特点,比较全面系统的介绍ODBC的基本概念以及DM4 ODBC DRIVER的使用方法,以便用户更好地使用DM4 ODBC编写应用程序.ODBC提供给你访 ...

  3. VC++ LoadLibrary失败,错误127(找不到指定的程序)

    该原因一般是由于DLL或其依赖的DLL使用了高版本的API,而运行时找不到dll中的函数导致的错误. 使用依赖工具查看可能是这样的情况:第一个依赖dll文件小方块中有红色 正常情况下,应该是这样: 解 ...

  4. C++变量命名方案

    变量命名方案和函数命名方案一样,也有很多话题可供讨论.确实,该主题会引发一些最尖锐的反对意见.同样,和函数名称一样,只要变量名合法,C++编译器就不会介意,但是一致/精确的个人命名约定是很有帮助的.与 ...

  5. 输入一个long类型的整数,输出一个以金融格式表示的字符串

    package test; public class Test { public static void main(String[] args) { System.out.println(yuan(1 ...

  6. oracle修改用户密码

    1.使用oracle用户登录,连接数据库 [oracle@wuzj ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Th ...

  7. 模拟window桌面实现

    正在开发中的游戏有个全屏功能--可以在window桌面背景上运行,就像一些视频播放器在桌面背景上播放一样的,花了个上午整了个Demo放出来留个纪念. 实现功能:显示图标,双击图标执行相应的程序,右击图 ...

  8. JZOJ.5289【NOIP2017模拟8.17】偷笑

    Description berber走进机房,边敲门边喊:“我是哔哔”CRAZY转过头:“我警告你,哔哔刚刚来过!”“呵呵呵呵……”这时,哔哔站了起来,环顾四周:“你们笑什么?……”巧了,发出笑声的人 ...

  9. [SCOI2010]传送带[三分]

    //point(AB)->point(CD) 距离满足下凸性,用三分套三分实现 #include<cmath> #include<cstdio> #include< ...

  10. Django学习笔记第三篇--关于响应返回

    一.返回简单类型: #1.返回简单字符串 #from django.http import HttpResponse return HttpResponse("return string&q ...