CF-832B
B. Petya and Examtime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputPrint 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.
Examplesinputab
a?a
2
aaa
aaboutputYES
NOinputabc
a?a?a*
4
abacaba
abaca
apapa
aaaaaxoutputNO
YES
NO
YESNoteIn 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".
题意:
首先给出的是good字母,第二行为标准句s,第三行为匹配串的个数n,其后跟n个串。
'?'可被替换为good字母,'*'可被替换为任意非good字符(包括空格)。
问充分运用规则后两串是否匹配。
AC代码:
#include<bits/stdc++.h>
using namespace std; const int maxn=1e5+;
int good[];
char s[maxn],p[maxn],a[]; int main(){
int n,pos=-;
cin>>a;
int len=strlen(a);
for(int i=;i<len;i++){
good[a[i]]++;
}
cin>>s;
len=strlen(s);
for(int i=;i<len;i++){
if(s[i]=='*'){
pos=i;
break;
}
}
cin>>n;
while(n--){
int flag=;
cin>>p;
int lenp=strlen(p);
if(pos==-){
if(len!=lenp){
cout<<"NO"<<endl;
flag=;
continue;
}
for(int i=;i<lenp;i++){
if(s[i]=='?'){
if(good[p[i]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
else if(s[i]!=p[i]){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(flag){
cout<<"YES"<<endl;
}
}
else{
if(len-lenp>=){
cout<<"NO"<<endl;
continue;
}
for(int i=;i<pos;i++){
if(s[i]=='?'){
if(good[p[i]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
else if(s[i]!=p[i]){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(!flag)continue;
int t=lenp-len+pos;//*替换的部分
for(int i=pos;i<=t;i++){
if(good[p[i]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(!flag)continue;
for(int i=len-,j=lenp-;i>pos;i--,j--){
if(s[i]=='?'){
if(good[p[j]]!=){
cout<<"NO"<<endl;
flag=;
break;
}
}
else if(s[i]!=p[j]){
cout<<"NO"<<endl;
flag=;
break;
}
}
if(flag)
cout<<"YES"<<endl;
}
}
return ;
}
CF-832B的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
随机推荐
- 怎样在C语言里实现“面向对象编程”
有人觉得面向对象是C++/Java这样的高级语言的专利,实际不是这样.面向对象作为一种设计方法.是不限制语言的.仅仅能说,用C++/Java这样的语法来实现面向对象会更easy.更自然一些. 在本节中 ...
- Android SQLite性能分析
作为Android预置的数据库模块,对SQLite的深入理解是很有必要的,能够从中找到一些优化的方向. 这里对SQLite的性能和内存进行了一些測试分析.对照了不同操作的运行性能和内存占用的情况,粗略 ...
- java基础&&高薪面试
董鹏老师 ,多年经验总结出 [高薪就业必备]之java基础面试题[更新中]: 第01篇 学习Java基础的目的? 第02天 java语言中有没有gotoke ...
- A20 烧录和启动 log
用 LiveSuit 烧写了一个 lubuntu 的映像文件到板子上, 同时接了串口观察烧录过程的串口打印信息, 如下 ES: FES:Fes Ver: 098 FES:=============== ...
- slidemenu
1. 在github上有一个效果不错的开源库,SlidingMenu 最新的代码下载下来后,会报错: No resource found that matches the given name: at ...
- mvc 发送QQ邮件
试图部分代码: @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } ...
- SAM4E单片机之旅——8、UART初步
通信还是比让LED灯闪烁实用得多的. 这次试试使用UART,实现开发版和PC间的通信.功能比较简单,就是把PC发向开发版的内容发送回去.这次主要介绍一下UART的配置,至于通信,则使用较为简单的不断查 ...
- Qt笔记之使用设计器自定义窗口标题栏
1.在窗口显示之前,设置WindowFlags为FramelessWindowHint,以产生一个没有边界的窗口 例如 Widget::Widget(QWidget *parent) : QWidge ...
- 时间操作(Java版)—获取给定日期N天后的日期
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/wangshuxuncom/article/details/34896777 获取给定 ...
- Process 'command 'D:\AndroidSDK\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2
解决方法: 在jni文件下建一个空的empty.c文件 编译运行即可. 如果还运行不了,在当前model的build.gradle下添加. android{ ………… sourceSets.main ...