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 ...
随机推荐
- c# 匿名反序列化
1.先new一个匿名对象,然后再反序列化好处是能点点点,坏处是得先new匿名对象 2.借用Newtonsoft.Json.Linq.JObject.Parse,好处是不需要new匿名对象,坏处是不能点 ...
- Maven 多项目依赖,需要验证artifact的output root中是否包含其他项目输出
- drawCall_01
在屏幕上渲染物体,引擎需要发出一个绘制调用来访问图形API(iOS系统中为OpenGL ES).每个绘制调用需要进行大量的工作来访问图形API,从而导致了CPU方面显著的性能开销. Unity在运 ...
- 浅谈千万级PV/IP规模高性能高并发网站架构(转自老男孩)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51cto.com/2561410/736710 如果把来 ...
- It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing ___Error Installing APK
一 : 根据以下路径,找到Instant Run中的选项 File —— Settings——Build,Execution,Deployment——Instant Run ...
- JavaScript Promise迷你书(中文版)
最近,发现了一个很不错的关于Promise介绍的迷你电子版书,分享给大家: http://liubin.org/promises-book/#chapter4-advanced-promise (篇幅 ...
- 【LeetCode OJ】Majority Element
题目:Given an array of size n, find the majority element. The majority element is the element that app ...
- print($arr,true)的参数true表示将$arr的值返会,而不是打印
之前通过error_log()来调试php, 发现收到的json字符前边总是有一个1,一直以为是哪里直接出现了print.print_r.echo.var_dump(), 后来发现原来是某处用了形如e ...
- 《转》Python学习(14)-对文件的操作(一)
转自 http://www.cnblogs.com/BeginMan/p/3166644.html 一.文件对象 我理解的文件对象就是一个接口,通过这个接口对文件进行相关操作. <Python ...
- 日记整理---->2016-11-25
2017-03-02开始,记录的一些知识点.岁月长,三更漏.漫漫回廊,依稀人空瘦.借酒消愁入断肠,倚剑笑我,我独自寻殇. 一.vx中的v-bind和{{}}的区别 <td class=" ...