补的若干年以前的题目,水题,太菜啦_(:з」∠)_ 
 
 
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;
const int N=1e5+;
char a[N],b[N],flag[N];
int main(){
int n;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(flag,,sizeof(flag));
while(~scanf("%s",a)){
int len1=strlen(a);
for(int i=;i<len1;i++)
flag[a[i]]=;
scanf("%s",a);
len1=strlen(a);
scanf("%d",&n);
while(n--){
memset(b,,sizeof(b));
scanf("%s",b);
int len2=strlen(b);
int i=,j=;
int cnt=,ret=;
while(i<len2){
if(a[j]=='*'){
for(int h=;h<len2-len1+;h++){ //直接特殊判断
if(flag[b[i]]==){cnt=;break;}
i++;
}
j++;
continue;
}
if(i>=len2)break;
i++;j++;
if((a[j-]=='?'&&flag[b[i-]]==)||a[j-]==b[i-]) //匹配'?'和字母直接匹配
continue;
ret=; //如果走到这一步,说明上面匹配的有不符合条件的
if(ret)break;
}
if(j<len1&&(len1-len2>||a[len1-]!='*')) //如果标准串比要匹配的串的长度>1,说明不是完全匹配
if(ret)printf("NO\n");
else printf("YES\n");
}
}
return ;
}

太菜啦,加油啦(╯°Д°)╯︵┻━┻

CodeForces832-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 832B Petya and Exam

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

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

  4. Codefroces 832B Petya and Exam

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

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

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

  6. B. Petya and Exam

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

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

  8. 832B Petya and Exam

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

  9. CF832B Petya and Exam

    思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...

随机推荐

  1. Python模块之pickle(列表,字典等复杂数据类型与二进制文件的转化)

    1.pickle模块简介 The pickle module implements binary protocols for serializing and de-serializing a Pyth ...

  2. UVALive 3716 DNA Regions

    题目大意:给定两个长度相等的字符串A和B,与一个百分比p%,求最长的.失配不超过p%的区间长度.O(nlogn). 题目比较简单套路,推推式子就好了. 记S[i]表示到下标i一共有多少个失配,就相当于 ...

  3. Spark源码剖析(六):Worker原理与源码剖析

    上篇文章我们剖析了Master的原理和源码,知道了当Master使用资源分配算法将资源分配完成后,就会给对应的Worker发送启动Driver或者Executor的消息,那么Worker收到这些消息后 ...

  4. js计算字数

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  5. tee 命令详解

    作用:将数据重定向到文件,另一方面还可以提供一份重定向数据的副本作为后续命令的stdin . 简单的说就是把数据重定向给文件和屏幕上. 注意:存在缓存机制,每1024 字节输出一次, 若从管道接受数据 ...

  6. windows日志监控

    bat脚本,主要作用,每个五分钟读取日文本件中新增内容,进行错误赛选,如果有错误信息,将错误信息用邮件发送给管理员. 其中awk和sed需要手动下载 :读取number.txt文档,获取上一次执行时文 ...

  7. ioutil包二

    ioutil包二 (原创随笔,转载请注明出处 http://www.cnblogs.com/majianguo/p/8016426.html) ioutil包实现了一些I/O实用功能,导出了7个函数和 ...

  8. 根据图片的路径(绝对路径/相对路径都可以),生成base64的

    根据图片的路径(绝对路径/相对路径都可以),生成base64的 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  9. redis资料收集

    http://www.runoob.com/redis/redis-sets.html  redis set 使用 https://www.cnblogs.com/wanzaixiaoxin/p/49 ...

  10. VS2010安装OpenGL

     以下涉及到的所有资源都在这里: 链接:https://pan.baidu.com/s/1eSctT5K 密码:174s *我的VS2010的安装位置:D:\Program Files (x86)\M ...