codeforces B. Petya and Exam (模拟)

TWR-K65F180M评估板:基于Cortex-M4的嵌入式原型开发实战指南 在嵌入式系统开发中,微控制器(MCU)是核心,而围绕其构建的硬件平台则是将想法转化为可工作原型的关键。Cortex-M4内核凭借其高效的流水线、DSP指令集和浮点单元,为实时控制与信号处理提供了强大的运算能力。其技术价值在于,能够在较低功耗下满足工业控制、物联网网关等场景对能效比的严苛要求。为了快速验证系统设计,开发者常使用成熟的评估板来规避底层硬件设计的风险,直接聚焦于应用开发。本文以恩智浦的TWR-K65F180M评估板为例,深入解析其基于**ARM Cortex-M4**内核的K65 MCU的硬件架构 阅读详情
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");
	}
}


【科学文献计量】标准参考出版年谱(Standard RPYS)和多维参考出版年谱(Multi RPYS) @[TOC](标准参考出版年谱(Standard RPYS)和多维参考出版年谱(Multi RPYS)) 1 标准参考出版年谱与多维参考出版年谱 1.1 标准参考出版年谱(Standard RPYS) 标准参考出版年谱(Standard Reference Publication Year Spectroscopy)是由Marx, Bornmann, Barth, and Leydesdorff(2014)和Marx and Bornmann(2014)提出的一种量化历史出版物对研究领域影响的方法。该方法通 阅读详情

相关推荐

飞行器坐标转换

本文定义的是右手直角坐标系,x−y−zx-y-zx−y−z轴分别为北-天-东。从AAA坐标系到BBB坐标系是分别绕y−z−xy-z-xy−z−x轴,即天-东-北旋转ψ−θ−γψ−θ−γ。如果AAA是惯性系,BBB是机体系,则这三个角度分别为偏航角、俯仰角、横滚角。图1 惯性系到机体系。

gongfuyd的博客 1360

#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

HarmonyOS开发第一步:Dev Eco Studio4.0保姆级安装配置指南(含Node.js环境)

本文提供HarmonyOS开发环境搭建的保姆级教程,重点详解Dev Eco Studio 4.0的安装与配置,并攻克Node.js环境与Ohpm包管理器的关键设置难点。通过清晰的步骤指引,帮助开发者从零开始,高效完成开发环境部署,顺利迈出鸿蒙应用开发的第一步。

lake5的博客 577

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的博客 314

大气层23.0.0整合包升级指南:解决unknow pkg1报错与双系统防误更新

自定义固件(CFW)通过劫持启动流程实现系统接管,其核心在于版本匹配与签名验证。当系统固件更新后,CFW必须同步更新核心文件与签名补丁,否则启动阶段会因版本不匹配而报错。双系统方案中,正版与虚拟系统固件独立,误更新正版系统会导致虚拟系统启动链断裂。正确做法是保持虚拟系统版本不低于正版,并严格对应大气层核心文件与签名补丁。本文围绕大气层23.0.0整合包,详解文件结构、安装顺序、Daybreak固件升级及防误更新策略,助你稳定运行自定义系统。

weixin_32075843的博客 522

openEuler 22.03 LTS SP4离线安装UKUI桌面全攻略(附依赖包下载)

本文提供openEuler 22.03 LTS SP4系统离线安装UKUI桌面环境的完整实战指南。针对无网络环境,详细解析了利用dnf工具下载依赖包、配置离线软件源、处理依赖冲突及安装后优化的全流程,并附带了关键依赖包资源,帮助运维人员高效完成图形化部署。

c7d8e9的博客 507

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的博客 862

Win10下ISE14.7 iMPACT闪退?三步搞定DLL替换(附详细路径)

本文详细介绍了在Windows 10系统下解决Xilinx ISE14.7 iMPACT工具闪退问题的三步DLL替换方案。通过替换关键DLL文件,有效解决了FPGA开发中的兼容性问题,帮助开发者快速恢复工作流程。

weixin_29290259的博客 598

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

使用Zed 实现测距

此代码基于官方代码基础上进行改写,主要是获取zed相机深度画面的深度值,为yolo测距打基础。Zed相机是由Stereolabs公司开发的一种先进的立体视觉相机。这种相机专为计算机视觉和机器学习应用而设计,能够提供高质量的3D捕捉和分析功能。: Zed相机配备有一对垂直排列的传感器,能够捕捉两个略有偏移的图像,从而模拟人的双眼视觉,实现深度感知。: 利用立体成像技术,Zed相机能够实时生成环境的3D模型,这对于机器人导航、增强现实(AR)和虚拟现实(VR)等应用至关重要。

weixin_45303602的博客 917

开发Qt上位机获取阿里云IOT设备数据(开发上位机对接阿里云IOT平台)

使用Qt框架开发一款上位机软件,调用阿里云物联网平台的API接口,获取设备最新上传的实时数据,并在Qt设计的软件界面上展示处理。同时,还支持绘制曲线图表展示数据,并具备定时刷新功能。

2147

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

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

zaiyang遇见 582

Open3D 可视化(1)——简单可视化【2026最新版】

简单可视化,博客长期更新,本文最新更新时间为:2026年5月10日。

点云侠的博客 5691

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 293

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Codeforces 832-B Petya and Exam (模拟)

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

SD_Stjean的博客 579

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

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的博客 519

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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震震的博客 570

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 459
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址