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 ...
随机推荐
- oop思维意识,类 模块命名空间,类扩展之继承 、组合、mixin三种模式
python的书都是讲怎么创建类怎么实例化对象,一般会用使用了,但还不具备这种编程意识.这是从python学习手册第四版节选出来的,书中说oop不仅是一种技术,更是一种经验.学习大神的看法,为什么需要 ...
- 字符串中包含汉字和\u,显示出汉字来
针对py2,py3不需要这样.#coding=utf8import sysreload(sys)sys.setdefaultencoding('utf8') strx2='你好\u4e2d\u56fd ...
- Office2007打开文件提示“您尝试打开的文件xxx.xls的格式与文件扩展名指定的格式不一致”的解决办法
添加如下注册表 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel ...
- 下拉刷新 上拉更多 支持ListView GridView WebView【转载】
转载自:http://www.stay4it.com/?p=245 老贴重发,源代码放附件了,需要的下载把. 终于有新货了.昨天改了下,在ListView和GridView加了个返回到顶部的按钮,li ...
- feed流拉取,读扩散,究竟是啥?
from:https://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=2651961214&idx=1&sn=5e80ad6f2 ...
- SpringMVC -- 梗概--源码--贰--mvc:annotation-driven
1>在springMVC的处理流程中,有两个重要组件:HandlerMapping和HandlerAdapter 分别负责解析Handler和执行Handler 2>如果配置了<mv ...
- 【代码审计】eduaskcms_v1.0.7前台存储型XSS漏洞分析
0x00 环境准备 eduaskcms官网:https://www.eduaskcms.xin 网站源码版本:eduaskcms-1.0.7 程序源码下载:https://www.eduaskcm ...
- Splash runjs() 方法
runjs() 方法可以执行 JavaScript 代码,它与 evaljs() 功能类似,但是更偏向于执行某些动作或声明某些方法 function main(splash, args) splash ...
- VS调试DLL代码使用”附加到进程“
如果一个DLL解决方案,被另一个DLL2解决方案依赖,DLL2被可执行程序exe1引用 如何调试DLL的代码断点呢 1.可以参考另一篇随笔DLL如何调试 2.先运行起来exe1,然后再DLL项目中”调 ...
- MQTT_DEMO
1 /* 2 Copyright (c) 2009-2012 Roger Light <roger@atchoo.org> 3 All rights reserved. 4 5 Redis ...