codeforces 832B
来源:互联网 发布:逍遥模拟器没网络 编辑:程序博客网 时间:2024/06/11 20: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 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.
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".
- 题意:给你一个好串s1,给你一个 ”可操作“ 的串s2,里面除了小写字母之外可能包含*,?两种字符,对于*可以替换为空串(什么都没有)也可以替换为一个坏串(不包含好串任何字母的串),给你n个询问的字符串,问你操作之后能不能匹配。
- 代码:
#include<bits/stdc++.h>using namespace std;int main(){ string s1, s2; while(cin >> s1 >> s2) { int n; scanf("%d", &n); int l, r; int ans = 0; for(int i = 0; i < s2.length(); i++) { if(s2[i] == '*') { r = i + 1; ans++; break; } } while(n--) { string s; cin >> s; int len1 = s1.length(); int len2 = s2.length(); int len = s.length(); bool flag1 = true; bool flag2 = true; if(!ans) { if(len != len2) { puts("NO"); continue; } for(int i = 0; i < len; i++) { if(s2[i] == '?') { int j; for(j = 0; j < len1; j++) { if(s[i] == s1[j]) { break; } } if(j == len1) { flag1 = false; break; } } else { if(s2[i] != s[i]) { flag1 = false; break; } } } if(!flag1) { puts("NO"); continue; } else { puts("YES"); continue; } } else { int cnt = 0; for(int i = 0; i < len2; i++) { if(s2[i] >= 'a' && s2[i] <= 'z') { if(s2[i] != s[cnt]) { flag2 = false; break; } cnt++; } if(s2[i] == '?') { int j; for(j = 0; j < len1; j++) { if(s[cnt] == s1[j]) { break; } } if(j == len1) { flag2 = false; break; } cnt++; } if(s2[i] == '*') { int t1,t2; t1=len-cnt; t2=len2-r; //printf("t1=%d t2=%d\n",t1,t2); while(t1!=t2) { int j; for(j = 0; j < len1; j++) { if(s[cnt] == s1[j]) { flag2 = false; break; } } cnt++; t1=len-cnt; if(cnt>len) { flag2 = false; break; } } } } if(!flag2) { puts("NO"); continue; } else { puts("YES"); continue; } } } } return 0;}
- codeforces 832B
- Codeforces 832B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 832B Petya and Exam
- codeforces 832B (Petya and Exam)
- CodeForces 832 B. Petya and Exam
- CodeForces-832B Petya and Exam
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- centos6.5的tensorflow安装跳坑
- math证明题
- 1020. 月饼 (25)
- Tell me the area HDU 1798
- Spring 三种方式注入
- codeforces 832B
- centos 开机启动tomcat
- 类之间的关系 声明类 20170724
- Android获取Manifest中<meta-data>元素的值
- SDUT-顺序表应用4:元素位置互换之逆置算法
- 局部二值模式(LBP)
- JAVA设计模式之抽象工厂模式
- Fiddler 详尽教程与抓取移动端数据包
- OC 属性的内存管理