cfRound425B. Petya and Exam
来源:互联网 发布:写作起名软件 编辑:程序博客网 时间:2024/05/22 03:28
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 onegood lowercase English letter, and the character "*" (if there is one) with any, including empty, string ofbad 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 to26 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 ins 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 than105.
Print n lines: in the i-th of them print "YES" if the pattern matches thei-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary.
aba?a2aaaaab
YESNO
abca?a?a*4abacabaabacaapapaaaaaax
NOYESNOYES
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>#define maxn 100010 using namespace std;char g[30],s[maxn],q[maxn];int M,L,N,good[30];int main(){scanf("%s",g);for(int i=0;g[i];i++) good[g[i]-'a']=1;scanf("%s %d",s,&N);M=strlen(s);int star=-1;for(int i=0;i<M;i++) if(s[i]=='*') star=i;for(int i=0;i<N;i++){ scanf("%s",q); L=strlen(q); if(star==-1){ if(L!=M){ printf("NO\n"); continue; } bool ok=true; for(int i=0;i<M;i++){ if(s[i]=='?'){ if(!good[q[i]-'a']) ok=false; } else{ if(s[i]!=q[i]) ok=false; } } if(ok) printf("YES\n"); else printf("NO\n");}else{if(L<M-1){printf("NO\n");continue;}bool ok=true;for(int i=0;i<star;i++){if(s[i]=='?'){if(!good[q[i]-'a'])ok=false;}else{if(s[i]!=q[i]) ok=false;}}int j=L-1;for(int i=M-1;i>star;i--,j--){if(s[i]=='?'){if(!good[q[j]-'a']) ok=false;}else{if(s[i]!=q[j]) ok=false;}}for(int i=star;i<=j;i++) if(good[q[i]-'a']) ok=false; if(ok)printf("YES\n"); else printf("NO\n");}}return 0;}
- cfRound425B. Petya and Exam
- Codeforces832B Petya and Exam
- Petya and Exam
- B. Petya and Exam
- B. Petya and Exam【字符串】
- cf Petya and Exam(暴力)
- B. Petya and Exam(思维)
- CodeForces 832B Petya and Exam
- codeforces B. Petya and Exam (模拟)
- cf 832B Petya and Exam
- codeforces 832B (Petya and Exam)
- CodeForces 832 B. Petya and Exam
- CodeForces-832B Petya and Exam
- Petya and Exam(Codeforces Round #425 (Div. 2))
- Codeforces Round #425 (Div. 2)B. Petya and Exam
- CodeFroces 823B. Petya and Exam(构造题)
- Codeforces Round #425 (Div. 2) B. Petya and Exam
- codeforces 832B ——Petya and Exam
- Java 获取系统中可用字体的名字
- 数据集(人数统计、密度分析)
- 存储
- 动态生成input绑定事件无效如:blur
- ajax后台套用两层JSONOBJECT返回到前台的方法
- cfRound425B. Petya and Exam
- uva227 puzzle
- 图片边角形
- HDU1201-18岁生日
- DATAKIT.CrossManager.2017.1.Win32_64 2CD
- 2017多校1 b hdu 6034
- C/S、B/S架构的区别
- jQuery 选择器 first-child和first-of-type、 last-child和last-of-type的区别
- 两个栈实现一个队列