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 ...
 
随机推荐
- jQuery模拟输出回车键
			
jQuery模拟输出回车键 学习了:https://zhidao.baidu.com/question/1753748968579760068.html 原文少了个r var e = jQuery.E ...
 - Android带索引联系人列表
			
网上Android联系人列表的样例也非常多,都和微信的联系人差点儿相同,因为项目用到了联系人列表索引功能(产品把字母item给去掉了),只是也还是好实现.这里我也来分享分享我的实现,免得以后忘了.那先 ...
 - java.util.logging.FileHandler
			
java.util.logging.FileHandler java自带的日志功能,FileHandler可以写日志到文件系统,并且自己维护日志的增删,比c++不知道强多少 FileHandler(f ...
 - Linux 桌面的 Dock 类程序
			
1.Cairo-Dock是一个Dock类软件,它支持OpenGL.提供动画及视觉效果的插件.新的Applet.重写配置面板.新增主题等功能. 2.Docky是从GNOME Do项目剥离出来的一个Doc ...
 - Node测试文章收藏
			
1.Nodejs实战—测试Node程序 讲解了TDD与BDD,TDD的基本原则,单元测试常用框架及使用,例如assert断言库, chai断言库, should.js断言库,断言库搭配测试框架(m ...
 - BZOJ一句话
			
一句话题解集合. 1061: [Noi2008]志愿者招募 单纯形,运用对偶原理转化过来,变成标准形然后单纯性裸上即可. #include<cmath> #include<cstdi ...
 - github连接报"ssh: connect to host github.com port 22: Connection timed out"错误
			
1. 异常 在连接github时,执行"ssh -T git@github.com" 命令时,出现 ssh: connect to host github.com port 22: ...
 - TCP的可靠性 窗口滑动 拥塞控制
			
看这篇文章: http://www.cnblogs.com/woaiyy/p/3554182.html 窗口滑动,如下图: 流量控制 流量控制方面主要有两个要点需要掌握.一是TCP利用滑动窗口实现流量 ...
 - Android设计模式(七)--原型模式
			
1.定义: 用原型实例指定创建对象种类,并通过拷贝这些原型创建新的对象. 2.目的: 从一个对象创建另外一个可定制的对象,而不须要知道不论什么创建细节. 3.作用: 3.1.简化对象的创建. 3.2 ...
 - QQ互联账号登录
			
本文说明的是依据某应用通过网页的qq信息来登录的过程.用途是利用QQ账号就能高速自己主动注冊并可以登录客户应用. 从webserver与腾讯server通信获取开房平台用户OpenID,再在应用ser ...