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

题意:

首先给出的是good字母,第二行为标准句s,第三行为匹配串的个数n,其后跟n个串。

'?'可被替换为good字母,'*'可被替换为任意非good字符(包括空格)。

问充分运用规则后两串是否匹配。

AC代码:

 #include<bits/stdc++.h>
using namespace std; const int maxn=1e5+;
int good[];
char s[maxn],p[maxn],a[]; int main(){
int n,pos=-;
cin>>a;
int len=strlen(a);
for(int i=;i<len;i++){
good[a[i]]++;
}
cin>>s;
len=strlen(s);
for(int i=;i<len;i++){
if(s[i]=='*'){
pos=i;
break;
}
}
cin>>n;
while(n--){
int flag=;
cin>>p;
int lenp=strlen(p);
if(pos==-){
if(len!=lenp){
cout<<"NO"<<endl;
flag=;
continue;
}
for(int i=;i<lenp;i++){
if(s[i]=='?'){
if(good[p[i]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
else if(s[i]!=p[i]){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(flag){
cout<<"YES"<<endl;
}
}
else{
if(len-lenp>=){
cout<<"NO"<<endl;
continue;
}
for(int i=;i<pos;i++){
if(s[i]=='?'){
if(good[p[i]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
else if(s[i]!=p[i]){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(!flag)continue;
int t=lenp-len+pos;//*替换的部分
for(int i=pos;i<=t;i++){
if(good[p[i]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(!flag)continue;
for(int i=len-,j=lenp-;i>pos;i--,j--){
if(s[i]=='?'){
if(good[p[j]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
else if(s[i]!=p[j]){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(flag)
cout<<"YES"<<endl;
}
}
return ;
}

CF-832B的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  10. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

随机推荐

  1. nightwatch testing 注意事项

    coding style 好的測試項目應該盡量不要使用pause 並且要有驗證的機制 .click('input.btn') //.pause(3000) .waitForElementVisible ...

  2. Ejb in action(六)——拦截器

    Ejb拦截器可以监听程序中的一个或全部方法.与Struts2中拦截器同名,并且他们都可以实现切面式服务.同一时候也与Spring中的AOP技术类似. 不同的是struts2的拦截器的实现原理是一层一层 ...

  3. 【Bootstrap】一个兼容IE8、谷歌等主流浏览器的受众门户式风格页面

    上一次写的<[Bootstrap]一个兼容IE8.谷歌等主流浏览器的受众巨幕式风格页面>(点击打开链接) 部分老一辈的需求可能对这样的后现代的风格并不惬意, 没关系,我们全然能够改变布局 ...

  4. idea常用的快捷命令

    main方法: psvm System.out.println(): sout

  5. div和img之间的缝隙问题

    这次做的项目,客户说.banner图的上下之间不要留有空隙,细致一看才发现,上下居然都有空隙.审查元素,发现全部的div,img的padding和margin都是0,对于这个间隙到底是假设产生的真的是 ...

  6. python--面向对象组合

    面向对象的命名空间 类中的方法   类中的静态属性   对象的属性类的组合应用 面向对象的命名空间 class A: country='中国' a=A() a.name='alex' print(a. ...

  7. byte数组和文件的相互转换

    /** * 获得指定文件的byte数组 */ private byte[] getBytes(String filePath){ byte[] buffer = null; try { File fi ...

  8. C++ 坑人系列(1): 让面试官晕倒的题目

     今天和几位同仁一起探讨了一下C++的一些基础知识,在座的同仁都是行家了,有的多次当过C++技术面试官.不过我出的题过于刁钻: 不是看起来太难,而是看起来极其容易,但是其实非常难! 结果一圈下来,3道 ...

  9. MVC3 类型 System.Web.Mvc.ModelClientValidationRule 同时存在

    用文本编辑器打开  工程名称 .csproj 找到 1. <Reference Include="System.Web.WebPages" /> 2. <Refe ...

  10. ffmpeg ffplay播放延时大问题:播放延时参数设置

    使用ffplay播放视频源时,rtsp/rtmp等,会有一定的延时,这里我们可以通过设置ffplay播放参数将延时控制到最小. ffplay.exe -i rtmp://xxxxxxx -fflags ...