codeforces B. Petya and Exam (模拟)

FPGA新手避坑指南:手把手教你搞定RTL8211千兆网PHY的时序配置(附Verilog代码) 本文详细解析了FPGA与RTL8211千兆网PHY芯片的时序配置问题,重点介绍了TXDLY/RXDLY引脚设置、FPGA发送端和接收端的Verilog实现,以及调试与验证的完整流程。通过硬件电路设计和代码示例,帮助开发者解决网络连接不稳定、丢包等常见问题,提升千兆网通信的稳定性。 阅读详情
B. Petya and Exam
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.

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
abc
a?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".

题目链接:http://codeforces.com/contest/832/problem/B
题目大意:第一行代表good word,第二行是模式串,?可以代替任意一个good word,*可以匹配为空,也可以代替任意一个全部都是bad word的子串,给定n个主串,问能否和模式串匹配,能就输出“YES”,不能就输出“NO”。
解题思路:模拟。难点在于*处的判断,考虑*匹配为空和为bad word的子串两种情况,注意除了*匹配的部分外,其他部分的字符是一一对应的,即其他部分的长度相等,可以从这一点入手。
代码如下:
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int a[26];
int main(void){
	string gd,s;
	cin >> gd;
	memset(a,0,sizeof(a));
	int len;
	len = gd.length();
	bool flog = false;
	for(int i=0;i<len;i++){   //标记good word
		a[gd[i]-'a'] = 1;
	}
	cin >> s;
	len = s.length();
	for(int i=0;i<len;i++){    //判断模式串中是否有*
		if(s[i]=='*'){
			flog = true;
			break;
		}
	} 
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		string cur;
		cin >> cur;
		bool p = true;
		int ls = s.length();
		int lc = cur.length();
		if(ls > lc+1 || ls == lc+1 && !flog ){  //如果模式串中没有*,串长相等才能匹配,如果有*,模式串串长要大于主串串长减1才匹配
			printf("NO\n");
			continue;
		}
		int k = 0;
		for(int j=0;j<ls,k<lc;j++,k++){
			if(s[j]<='z' && s[j] >= 'a'){   //主串的字母要和模式串的字母匹配
				if(s[j] != cur[k]){
					p = false;
					break;
				}
			}
			else if(s[j] == '?'){        //?匹配good word
				int x = cur[k]-'a';
				if(!a[x]){
					p = false;
					break;
				}
			}
			else if(s[j] == '*'){      
				int x = cur[k]-'a';
				for( ;k < lc-(ls-j)+1 ; k++){ //*后面剩下的长度要相等才匹配
					x = cur[k]-'a';
					if(a[x]){          //*匹配bad word
						p = false;
						break;
					}
				}
				if(p){
					if(lc - k < ls - j )   //*匹配为空的情况
						k--;
					continue;
				}
			}
			if(j == ls-1 && k < lc-1){
				p = false;
				break;
			}
			if(k == lc-1 && (j < ls-2 || j == ls-2 && s[ls-1]!='*')){
				p = false;
				break;
			}
 		}
		if(p)
			printf("YES\n");
		else
			printf("NO\n");
	}
}


Underactuated Robotics - 欠驱动机器人学(一)- 全驱动与欠驱动系统 根据牛顿的观点,机械系统的动力学是二阶的(其状态由位置向量 q(也称为配置向量)和速度向量以及(可能还有)时间给出。二阶控制动力系统的一般形式是:其中 u 是控制向量。定义 1.1 (欠驱动控制微分方程) 二阶控制微分方程描述如下:在状态和时间 t 中,如果所得到的映射是可射的:对于每一个,都存在一个能产生预期响应的,那么系统就是全驱动的。否则,就是欠驱动(状态在时间 t)。 阅读详情

相关推荐

团结引擎+OpenHarmony 记录 (持续更新中)

获取不到的原因是因为二者不在同一个线程中,所以数据没有同步。而 globalThis.context 数据进行了同步。(TuanjieMainWorkerHandler.ts中可以看到)在进行绘制 UI 的时候 ,如果组件有 Native API 就可能不会显示出来,例如 web 控件就不能展示出来,刚加上权限的时候 会报错 因为缺少 reason ,添加上就不会报错了。只有纯 UI 控件是可以展示出来的,注释掉 web控件后就可以。

m_cainiaokuaifei的博客 1490

#425

B. Petya and ExamIt’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 wit

Code_Diary的博客 518

Ubuntu虚拟机IP卡在127.0.0.1?别慌,试试这条万能命令 `sudo dhclient`

本文详细解析了Ubuntu虚拟机IP卡在127.0.0.1的常见原因及解决方案,重点介绍了`sudo dhclient`命令的使用方法及其变体,帮助用户快速恢复网络连接。同时提供了网络诊断工具和预防措施,适用于开发者和系统管理员应对网络故障。

weixin_29251131的博客 283

B. Petya and Exam

B. Petya and Examtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's hard times now. Today Petya needs to score 100 points on Informatics exam. T...

dreamjay1997的博客 312

【C#】控制设备管理器中设备的启用/禁用_20220506

通过C#代码实现设备管理器的启用/停止 引入Manamger程序集,查找到所需设备,控制启停

weixin_45475139的博客 4527

【深度学习面试八股文】-- 1-5

1.样本不平衡的处理方法 ①欠采样 - 随机删除观测数量足够多的类,使得两个类别间的相对比例是显著的。虽然这种方法使用起来非常简单,但很有可能被我们删除了的数据包含着预测类的重要信息。 ②过采样 - 对于不平衡的类别,我们使用拷贝现有样本的方法随机增加观测数量。理想情况下这种方法给了我们足够的样本数,但过采样可能导致过拟合训练数据。 ③合成采样( SMOTE )-该技术要求我们用合成方法得到不平衡类别的观测,该技术与现有的使用最近邻分类方法很类似。问题在于当一个类别的观测数量极度稀少时该怎...

m0_37940804的博客 9937

CF1282 C. Petya and Exam(贪心)

Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes. The exam consists of ???? problems that can be solve...

tomjobs的博客 861

光电振荡器(OEO):从原理到应用,解锁高频微波信号新纪元

本文深入解析了光电振荡器(OEO)的核心原理与前沿应用。OEO通过巧妙的光-电-光转换机制,利用光学谐振腔产生高频、高纯度、低相位噪声的微波信号,有效突破了传统电子电路的频率瓶颈。文章详细拆解了其工作流程,并探讨了在雷达系统、高速光通信及精密测量等领域的硬核应用价值。

weixin_29231027的博客 364

CodeForces - 1256B Minimize the Permutation(思维模拟)

题目链接:https://vjudge.net/contest/341054#problem/B 解析: 长度为n的一个排列(这个排列为n个数,从1到n) 最多进行n-1次操作 对于第i次操作,可以交换i和i+1位置上的数字 每一个位置交换后,就不能再进行交换了。 保证进行若干次操作后,能有最小的排列。输出这个最小的排列。 分析: 首先明白长度相同的两个序列,Note中的解释很好的说明了如何判...

zaiyang遇见 577

Python金融数据获取工具库之baostock使用详解

在金融数据分析和量化交易中,获取准确及时的市场数据是非常重要的。baostock是一个专门为中国股市数据提供支持的 Python 库,它提供了免费的股票数据接口,用户可以方便地获取股票、指数、基金等各种金融数据。本文将详细介绍baostock库,包括其安装方法、主要特性、基本和高级功能,以及实际应用场景,帮助全面了解并掌握该库的使用。

Rocky006的博客 5340

YOLOv13全网首发:CVPR2026 MixerCSeg | DEGConv方向引导边缘门控,破解细长裂缝检测难题

DEGConv通过方向先验嵌入、边缘增强卷积和动态门控三大机制,针对性解决了YOLO在处理裂缝类细长、多方向、低对比度目标时的特征提取不足问题,显著提升了裂缝检测的精度与鲁棒性。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 438

Codeforces 1256B Minimize the Permutation

思路: 贪心算法,每次找能移动的最小的数字往前移 代码: #include<bits/stdc++.h> using namespace std; typedef pair<int,int> p; typedef long long ll; #define isOp(x,y) ((x^y)<0) #define m_p(a,b) make_pair(a,b) #def...

Yuhan的博客 388

Hermes 教程 03:Skills 系统

摘要:Hermes Skills是一种自我改进机制,可将解决问题的经验保存为可复用技能文档。v0.13.0版本遵循agentskills.io开放标准,与Claude Skills互通。技能创建流程包括发现问题、创建技能文件、加载使用和优化更新四个阶段。系统提供技能检索和自维护机制(Curator),支持技能媒体路由和多种管理命令。内置技能涵盖开发调试、创意头脑风暴等场景,通过积累技能使Hermes更适应用户需求。

程序猿_三产 725

CodeForces - 832B Petya and Exam (模拟)

Petya and Exam 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 ...

YOONGI 292

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Codeforces 832-B Petya and Exam (模拟)

题目链接: http://codeforces.com/contest/832/problem/B题目大意: 给定一个匹配串A,和许多待匹配串,询问每次两个串之间是否完全匹配,其中给出good character字符集,字符只能与字符匹配,?只能与一个good字符匹配,*可以与空串或者bad character组成的串匹配分析: 直接模拟即可,可以分成匹配串有*和没有*两种情况,没有*的话,可

SD_Stjean的博客 579

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

E - Petya and Exam CodeForces - 832B(字符串模拟)

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 ...

tomjobs的博客 518

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

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 memory limit per test 256 megabytes input standard input output standard output It'...

weixin_30425949的博客 132

CodeForces 832B Round #425 Div2 B Petya and Exam:双指针暴力模拟

题意:全字符集为‘a’..'z'。现给出一个名叫good的子集,其补集定义为bad,给出模式串s,其中s可能有多个‘?’(可以被替换成任何一个good字符),至多一个‘*’(可以被替换成任意长度的bad串,可以为空),然后给出q次询问,每次询问一个匹配串t能否和s匹配成功。 题解:双指针模拟一下。。。emmm确实这个思路以前都没有尝试过。。WA了这么多次也算学到了一些新东西。 Code:

辣鸡葫芦娃 809

Codeforces Round #425 (Div. 2) B. Petya and Exam【模拟】

B. Petya and Exam【模拟】题意:给你一串字母,这些字母都是good字符,其余的小写字母都是bad字符 再给你一个模式串,包括小写字母,'*'和'?'三种。 其中‘?’只能由一个good字符代替,‘*’只能由若干个或者0个bad字符代替。 接下来给你N个字符串,判断这些字符串能否匹配模式串。思路:1.如果模式串不包括'*'。 1)模式串和匹配串的长度一定要相等,不相等NO,相等

zehong1995的博客 399

Codeforces 832B - Petya and Exam

本题是模拟题,问题出在匹配串的*上,给出的串分别与匹配串左右两边比较是否符合题意即可。注意特判去掉*之后的长度是否相同 #include #include using namespace std; const int N = 1e5 + 10; char s1[N],s2[N],s3[N]; int g[30]; int main() { int n,len1,len2; sca

zhlbjtu2016的博客 382

codeforces Petya and Exam(模拟+哈希+细心分析)

题目链接:http://codeforces.com/contest/832/problem/B 题目大意:给出一个字符串,判断这个字符串是否合理,合理就输出yes 题目思路:对于?号和*号的位置需要用到hash存储,26个字母也类似,然后就开始判断,最清晰的思路应该是分析查询串是否含*号,以及查询串与母串长度的关系,从而做出相应的判断。 学到的东西:这类模拟题目要细心,把逻辑分析清楚再做相

china震震的博客 569

CodeForces-832B Petya and Exam

根据题意模拟匹配就好 #include #include #include #include #include #include #include #include #include #include #include #include //#pragma comment(linker, "/STACK:1024000000,1024000000") #define IN

Lllll_sh的博客 303

Codeforces 832B: Petya and Exam

题目链接 暴力模拟。。好好读题就好了。。羡慕英语好的 #include<bits/stdc++.h> using namespace std; typedef long long LL; bool vis[150]; string t; string p,p1; int q; bool ok(string t) { if(t.length()&...

weixin_34061042的博客 116

Codeforces Round #425 (Div. 2)B. Petya and Exam

简单模拟。一开始读错题了。以为*代表随便一个字符(可以是空字符)后来发现是多个字符。而且还是坏的。 时间不多了(打早训不是cf)然后要替代多个字符※又有可能在中间我就蒙了。然后就不知道咋做。 后来发现只有一个型号。如果有这个型号的话型号的个数通过两个字符相减就可以得了。然后简单模拟一下就可以了。 小经验:当判断复杂的时候到函数里return。 #include <iostream> #...

weixin_43331783的博客 157

Codeforces Round #425 (Div. 2) B. Petya and Exam

题目链接:Petya and Exam题目大意:首先有两个字符串,一个字符串代表好字符串,这里面的每个字符都是好的(只包含小写字母),然后有一个原串,这个原串中可能包含有?和* 。?可以替换任意一个好字符,*可以替换空或者一个全由坏字符组成的串,接下来有t组数据,每组一个字符串,问这个字符串能不能通过上面的规则实现原串到模式串的替换题目思路:直接模拟就好,如果没有* 直接暴力替换,有的话从前往后替换

Nemaleswang的博客 337

CodeForces - 111C Petya and Spiders

题意:给你一个N * M个的格子 每个格子上有一个蜘蛛 每个蜘蛛可以进行5个动作 1不动2向左3向右4向上5向下 n * m的矩形== m * n的矩形减小状态数目 逆向思维放入k个蜘蛛把所有点占据满 蜘蛛最多能影响上一行的状态 用二进制模拟 ACcode: #include<bits/stdc++.h> using namespace std; cons...

HydraHuYu 458
上一篇: leetcode 22. Generate Parentheses
下一篇: hdu 1864 最大报销额 (01背包)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值