CodeForces832-B. 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".
题意就是:下面的字符串匹配给出的标准的字符串,标准的字符串中如果是'?',就找“好的”字符串中的一个,匹配一下。如果是'*',就是“好的”字符串的补集或者为空。
本来想的是如果有'*',就把'*'之前的匹配一下,再从后面匹配一下,剩下的特殊判断就可以。
但是太菜,写的代码太长啦,还老是写错,看了一下题解,可以直接依次判断匹配下去。
贴一下大佬代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
char a[N],b[N],flag[N];
int main(){
int n;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(flag,,sizeof(flag));
while(~scanf("%s",a)){
int len1=strlen(a);
for(int i=;i<len1;i++)
flag[a[i]]=;
scanf("%s",a);
len1=strlen(a);
scanf("%d",&n);
while(n--){
memset(b,,sizeof(b));
scanf("%s",b);
int len2=strlen(b);
int i=,j=;
int cnt=,ret=;
while(i<len2){
if(a[j]=='*'){
for(int h=;h<len2-len1+;h++){ //直接特殊判断
if(flag[b[i]]==){cnt=;break;}
i++;
}
j++;
continue;
}
if(i>=len2)break;
i++;j++;
if((a[j-]=='?'&&flag[b[i-]]==)||a[j-]==b[i-]) //匹配'?'和字母直接匹配
continue;
ret=; //如果走到这一步,说明上面匹配的有不符合条件的
if(ret)break;
}
if(j<len1&&(len1-len2>||a[len1-]!='*')) //如果标准串比要匹配的串的长度>1,说明不是完全匹配
if(ret)printf("NO\n");
else printf("YES\n");
}
}
return ;
}
太菜啦,加油啦(╯°Д°)╯︵┻━┻
CodeForces832-B. Petya and Exam的更多相关文章
- 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 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- Codefroces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- 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 ...
- 832B Petya and Exam
题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...
- CF832B Petya and Exam
思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...
随机推荐
- 树形dp系列
1.火车站开饭店 最大独立集裸题 #include<iostream> #include<cstdio> #include<cstdlib> #include< ...
- find + xargs + cp 遇到文件名中带空格如何处理
一,需求为查询文件名为ZRSH开头的时间为7月至今的所有文件并打包 1.首先想到的就是find + xargs + cp 格式.. find 2016073* -type f -name *ZRS ...
- MySQL集群PXC的搭建
MySQL集群PXC的搭建 最近公司某客户要求我们的数据库搭建PXC集群以保证他们的系统高性能和搞稳定性 以后花费了一些时间去搭建和测试,也踩过一些坑,准备分享出来 系统:centos6.6PXC:5 ...
- 【转】java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
最近在配置最新的ssh(struts2.3.16.3+hibernate4.3.7+spring4.1.2)的时候遇到的这个错误提示,后来在网上找了半天都不能解决,虽然有个说法是model对象用这样@ ...
- java log4j基本配置及日志级别配置详解
java log4j日志级别配置详解 1.1 前言 说出来真是丢脸,最近被公司派到客户公司面试外包开发岗位,本来准备了什么redis.rabbitMQ.SSM框架的相关面试题以及自己做过的一些项目回顾 ...
- Vuex- Action的 { commit }
Vuex 中 使用 Action 处理异步请求时,常规写法如下: getMenuAction:(context) =>{ context.commit('SET_MENU_LIST',['承保2 ...
- 解决ios手机上传竖拍照片旋转90度问题
html5+canvas进行移动端手机照片上传时,发现ios手机上传竖拍照片会逆时针旋转90度,横拍照片无此问题:Android手机没这个问题. 因此解决这个问题的思路是:获取到照片拍摄的方向角,对非 ...
- checkbox对齐-复选框图标
checkbox对齐-复选框图标 一般开发过程中,我们直接使用<input type="checkbox"/>这样出现的复选框,设计师一般都说不好看 而让我们按照设计稿 ...
- BCB F12切换界面 显示异常
亲们,我偶遇了一个小怪兽F12切换界面,效果如下: 还没有解决办法:
- Ajax的请求方式几传参的区别
Get,Post,Put,Delete请求(ajax)方式的不通. http://blog.jobbole.com/99854/