题目链接
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.

Input
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.
Output
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.
Examples
Input

ab
a?a

2

aaa
aab

Output
YES
NO
Input

  abca?a?a*4
abacaba
abaca
apapa
aaaaax

Output
NO
YES
NO
YES
Note
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”.

题意:
1.第一个给出的字符串a是由不同的小写英文字母组成。这些字母都是好字母,其它都是不好字母;
2.给的是一个语句(或者说字符串b),并且b中有一个glob模式(一个由小写英文字母组成的字符串,字符“?”“*”)。众所周知,字符“*”在glob模式中不会出现一次。
3.给出了一个数n代表有n个查询字符串;
n个查询字符串,需要为每个查询字符串确定模式是否匹配。

字符“?”可以用一个好字母替换;字符“*”(如果有的话)可以用任何(包括空的)坏的小写英文字母串;

如果能使替换成功使得他们一样成为glob模式则匹配成功输出YES,否则输出NO;
翻译:
输入
第一行包含一个长度为1到26的字符串,由不同的小写英文字母组成。这些字母是好字母,其他字母都不好。
第二行包含模式 - 一个由小写英文字母组成的字符串,字符“?”和“”(1≤| s |≤105)。保证字符“”在s中出现不超过一次。
第三行包含整数n(1≤n≤105) - 查询字符串的数量。
接下来是n行,每行包含由小写英文字母组成的单个非空字符串 - 查询字符串。

解题思路:模拟;

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=100500;
char a[500],b[N],s[N];
int vis[500];
int cnt;
int main()
{cin>>a>>b;int n;int k=strlen(a),m=strlen(b),cnt=0;for(int i=0; i<k; i++)//开一个数组标记好字母;{vis[a[i]]=1;}for(int i=0; i<m; i++)//记下出现*的次数;{if(b[i]=='*')cnt++;}scanf("%d",&n);while(n--){int flag=1;cin>>s;int len=strlen(s);if(cnt==0&&len!=m)//如果*在s中没有出现过,则判断s与b字符串长度是否相等;printf("NO\n");else if(cnt==1&&m-len>1)//如果出现一次,b字符串的长度比s超过1则必不能匹配;cout<<"NO"<<endl;else{int is=0,ib=0,l=len-m+1;//可能存在s长度比b多很多,它有可能是一个包括任何(包括空的)坏的小写英文字母串组成;while(is<len)//查找{if(flag==0)//结束break;if(b[ib]!='?'&&b[ib]!='*')//当b不是?或者*时,只要s与b的对应位置的字母不相同,必不匹配;{if(s[is]!=b[ib]){flag=0;cout<<"NO"<<endl;break;}}else if(b[ib]=='?')//当b出现?时,判断vis标记的为零则必不匹配;{if(vis[s[is]]==0){flag=0;cout<<"No"<<endl;break;}}else if(b[ib]=='*')//为*{for(int j=0; j<l; j++){if(vis[s[is+j]]==1){flag=0;cout<<"NO"<<endl;break;}}is=is+l-1;//注意这时,is需要移位,其实本质是为了与ib对应:相当于删了那些坏的任何(包括空的)坏的小写英文字母串;然后继续判断;}is++,ib++;}if(flag)printf("YES\n");}}return 0;
}

B. Petya and Exam相关推荐

  1. C. Petya and Exam

    C. Petya and Exam 题目链接 题目大意,考试t个小时,n个题,简单题要用a个小时,难题要花b个小时,每题1分,可随时交卷,但考试过程中会随着时间的延长,题目会变成必做题,如果交卷时必做 ...

  2. Petya and Exam(字符串模拟)

    Petya and Exam - CodeForces 832B - Virtual Judge (csgrandeur.cn) 题意:给你一个好的字符串和一个模式串,模式串里面的?可以替换成任意的好 ...

  3. Petya and Exam

    Description It's hard times now. Today Petya needs to score 100 points on Informatics exam. The task ...

  4. Petya and Exam 模拟

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  5. 【翻译】旧技术成就新勒索软件,Petya添加蠕虫特性

    原文链接:https://blogs.technet.microsoft.com/mmpc/2017/06/27/new-ransomware-old-techniques-petya-adds-wo ...

  6. 9A0-054 Exam 专业认证

    Adobe Photoshop CS3 ACE Exam 科目编号:9A0-054 科目名称:Adobe Photoshop CS3 ACE Exam 考题数目:148 Q&As 更新日期:2 ...

  7. 【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. cfa mock exam 2020下载_2019年6月CFA考试为什么一定要做MOCK?

    CFA备考是要注意认真看书的,不过也不能忽视掉做题的重要性,尤其是要有做历年CFA mock的准备,官方mock exam接近真题,mock exam考试难度.结构.考点.形式都基本和正式CFA考试一 ...

  9. A watermeten 《Before an Exam》

    这是第二次参加的网络比赛,虽然是内部的,但也体会了一把比赛的感觉:题目比上次简单多了,会做的也不少,现在把其中我做的问题拿出来分析一下: A. <Watermelon> time limi ...

最新文章

  1. 3 html语言是什么,HTML语言剖析(3)
  2. 网站推广——网站推广专员在优化网站中都有哪些技巧呢?
  3. python drawline_基于python,OPenCv中基本的绘图函数
  4. 100. Same Tree 相同的树
  5. mybatis里的log适配器模式
  6. 浙大PAT甲级1027. Colors in Mars (20)
  7. 全新 ENVI Modeler 遥感建模工具
  8. 小球碰撞python代码_Java 实现小球碰撞GUI
  9. 国有数据要素市场的政策红利,你get 到了吗?
  10. android 拍照和选择相册图片剪切
  11. 【科目一】你必须知道的驾考交通标志大全
  12. 鼠标双击桌面上的快捷方式出现打开本快捷方式属性,而不是打开文件的可能原因及解决方法参考...
  13. Spring Security 强制退出指定用户
  14. python并集符号_Python No.18_集合以及表示符号
  15. vue-echarts绘制地图轮廓
  16. NFT Insider #43 Animoca Brands完成3.58亿美元融资,微软重金收购暴雪
  17. 影院活动管理系统需求分析报告
  18. LeetCode 2423. Remove Letter To Equalize Frequency【哈希表】简单
  19. opengl纹理颠倒,rgb通道错位等。详解rgba,bgra,argb等内存序
  20. 石墨烯 量子计算机,石墨烯鼓有望成为量子计算机内存

热门文章

  1. Excel的官方网站
  2. 【AI绘画】绝美春天插画,人人都是插画师
  3. COPC酞菁钴,cAS号:3317-67-7磺化酞菁钴 催化剂 深蓝色粉末 磺化酞菁钴
  4. 计算机屏幕闪烁黑屏,台式机电脑。显示屏指示灯一直闪烁,屏幕黑屏。。...-显示器电源灯闪黑屏...
  5. R语言统计与绘图:生存曲线的两两比较
  6. RocketMQ广播消费与集群消费
  7. 初入职场,菜鸟北漂记
  8. 计算机中的同步和异步
  9. rsa私钥 txt转化为pem格式
  10. spark封神之路(1)-spark简介