CodeForces 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
#include <iostream> #include <string.h> #include <stdlib.h> #include <algorithm> #include <math.h> #include <stdio.h> #include <string> using namespace std; typedef long long int LL; const int maxn=1e5; char a[maxn+5]; char b[maxn+5]; int c[30]; char s[30]; int n; int main() { memset(c,0,sizeof(c)); scanf("%s",s); for(int i=0;s[i];i++) { c[s[i]-'a']=1; } scanf("%s",a); scanf("%d\n",&n); int len=strlen(a); for(int i=0;i<n;i++) { scanf("%s",b); int len2=strlen(b); int res=len2-len; if(res<-1) { printf("NO\n"); continue; } int j=0,k=0; bool ans=true; while(j<len||k<len2) { if(a[j]!='?'&&a[j]!='*') { if(a[j]!=b[k]) { ans=false; break; } else { j++,k++; continue; } } else if(a[j]=='?') { if(c[b[k]-'a']==1) { j++,k++; continue; } else { ans=false; break; } } else { if(res==-1) { j++; continue; } else { for(int p=k;p<=k+res;p++) { if(c[b[p]-'a']==1) { ans=false; } } if(ans==false) break; else { j++; k+=(res+1); continue; } } } } if(ans==true) printf("YES\n"); else printf("NO\n"); } return 0;}
CodeForces 832B Petya and Exam的更多相关文章
- Codefroces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- codeforces 1282C. Petya and Exam (贪心)
链接:https://codeforces.com/contest/1282/problem/C 题意: 有一个人参加考试,考试只有两种题,一种是简单题,每道题耗时固定为a:另一种是困难题,每道题耗 ...
- 832B Petya and Exam
题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- 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 ...
- CodeForces832-B. Petya and Exam
补的若干年以前的题目,水题,太菜啦_(:з」∠)_ B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...
- 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 ...
随机推荐
- HTML5 标准规范完成了
万维网联盟(W3C)昨天宣布,HTML5 标准规范终于最终制定完成了,并已公开发布.对于前端工程师来说,这无疑是一个振奋人心的好消息. 众所周知,HTML5改变了互联网,将成为 ...
- Springboot @webfilter @order filter过滤器
我们使用@WebFilter注解的时候发现注解里面没有提供可以控制执行顺序的参数 @WebFilter 的属性 属性名 类型 描述 filterName String 指定过滤器的 name 属性,等 ...
- Apache性能优化总结
1.介绍 首先要了解Apache采用的MPM(Multi -Processing Modules,多道处理模块),MPM是Apache的核心,它的作用是管理网络连接.调度请求.Apache2.0中MP ...
- NetBpm 示例:请假审批(6)
转载注明出处: http://www.cnblogs.com/anbylau2130/p/3877983.html 原文: 请假示例 流程定义包源码下载(注:par包就是zip格式压缩包).原文地址: ...
- 7代CPU安装win7的方法
7代CPU安装win7会遇到的问题: 32位的win7不支持uefi启动,64位win7理论上支持uefi启动,但实际上需要开启兼容模式才能启动,并且启动速度并没有变快. 根据不同型号的主板,需要解决 ...
- 【数据分析】Superset 之一 准备
https://segmentfault.com/a/1190000005083953 http://blog.csdn.net/bingoxubin/article/details/78583165 ...
- 【ArcGIS】ArcGIS Data Store配置
一.错误提示 Unable to configure the ArcGIS Data Store with the GIS Server. Please make sure that the GIS ...
- composer 更新指定包
1)网上搜了大半天都不知道怎么更新 componser 包,update upgrade 命令根本不知道怎么用!! 2)其实用 require 命令就可以更新包(它会判断包存不存在,不存在就安装,存在 ...
- 嵌入式ROOTFS transplantation
作一个嵌入式Linux rootfs,并且实现 web 服务 1. 文件系统简介 •理论上说一个嵌入式设备如果内核能够运行起来,且不需要运行用户进程的话,是不需要文件系统的,文件系统简单的说就是一种目 ...
- 使用react进行父子组件传值
在单页面里面,父子组件传值是比较常见的,之前一直用vue开发,今天研究了一下react的父子组件传值,和vue差不多的思路,父组件向子组件传值,父通过初始state,子组件通过this.props进行 ...