Codefroces 832B Petya and Exam
2 seconds
256 megabytes
standard input
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.
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.
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.
ab
a?a
2
aaa
aab
YES
NO
abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax
NO
YES
NO
YES
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".
模拟题,注意如果模式串中没有*,串长相等才能匹配,如果有*,模式串串长要大于主串串长减1才匹配
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,i,j,al,bl,y;
string a,b,c(,);
int main()
{
cin>>a;
for(int k=;k<a.size();k++)
{
c[a[k]]=;
}
cin>>a;al=a.size();
cin>>n;
while(n--)
{
cin>>b;bl=b.size();y=;
for(i=j=;y && i<al;i++)//没有*模式串匹配穿必须长度相等。
{
if(a[i]=='*')//有*模式串要大于主串串长减一才行,可以匹配为空
{
while(j<bl-(al-i-))
if(c[b[j++]]) y=;
}
else if(a[i]=='?'?c[b[j]]:a[i]==b[j])
j<bl?j++:y=;
else y=;
}
if(j<bl) y=;
puts(y?"YES":"NO");
}
return ;
}
Codefroces 832B Petya and Exam的更多相关文章
- CodeForces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 832B Petya and Exam
题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- CodeForces832-B. Petya and Exam
补的若干年以前的题目,水题,太菜啦_(:з」∠)_ B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...
- 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 ...
- 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 ...
- B. Petya and Exam
B. Petya and Exam 题目链接 题意 给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符, 然后给你另一串字符,这个字符串中有两个特殊的字符, ...
- 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 ...
- CF832B Petya and Exam
思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...
随机推荐
- C++里面关于虚函数的一些注意点
最后,总结一下关于虚函数的一些常见问题: 1) 虚函数是动态绑定的,也就是说,使用虚函数的指针和引用能够正确找到实际类的对应函数,而不是执行定义类的函数.这是虚函数的基本功能,就不再解释了. 2) 构 ...
- 小贝_php+redis类型组合使用
php_redis类型组合使用 一.类型组合说明 经过前面的文章介绍.已经知道redis有字符串.集合.列表.hash等内置数据类型. 这里以,无序集合为例,进行说明. 集合 set1的简图 1.从简 ...
- 【Linux】JDK+Eclipse 搭建C/C++开发环境
注:本文所提供的参考示例是在CentOS Linux环境下的安装,不保证适用于其他版本的Linux系统. · 安装前的注意事项 编译源代码是需要对应的代码编译工具的,本文中安装的Eclipse只 ...
- 异常Exception
try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解.不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单.听话.不信?那你看 ...
- BZOJ 3631 链剖+差分
思路: 1.树链剖分+用带标记的线段树维护操作(复杂度O(nlog2n)) 2.树链剖分LCA(TarjanLCA等各种LCA)+差分 复杂度(O(n)->O(nlogn)之间) 下面就说说怎么 ...
- PL/SQL Developer怎么连接远程数据库
首先打开电脑,到PL/SQL安装的指定目录 [D:\app\DZL\product\10.2.0\dbhome_1\NETWORK\ADMIN]或者[D:\oracle\product\10.2.0\ ...
- 图解RHEL6从安装光盘中进行yum安装
图解RHEL6从安装光盘中进行yum安装 导读:我们这里讲的Yum,是Yellow dog Updater, Modified的缩写,可执行程序名为yum,它的理念是使用一个中心仓库(reposito ...
- tomcat7 bootstrap
tomcat7 bootstrap http://t5crambing.iteye.com/blog/1923636
- springMVC No mapping found for HTTP request with URI
转载自:http://blog.sina.com.cn/s/blog_534f69a00101332u.html 1.问题: No mapping found for HTTP request wit ...
- 对比《动手学深度学习》 PDF代码+《神经网络与深度学习 》PDF
随着AlphaGo与李世石大战的落幕,人工智能成为话题焦点.AlphaGo背后的工作原理"深度学习"也跳入大众的视野.什么是深度学习,什么是神经网络,为何一段程序在精密的围棋大赛中 ...