B. Petya and Exam
B. Petya and Exam
题意
给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符,
然后给你另一串字符,这个字符串中有两个特殊的字符,一个是\(?\)这个字符只能被\(good\)字符代替,另一个是\(*\)这个能被忽略,或者被\(bad\)字符组成的字符串代替.
然后给你n个字符串,问你是否能通过代替原本串中的符号来变得。
思路
首先判断原本串中是否存在\(*\)字符如果不存在,那么下面的串的长度就应该和原本串的长度相等。如果存在的话,那么要检查的串的长度必须大于等于原串的长度-1。
然后贪心判定,两串同时从头开始扫,如果原本串中的为\(*\)那么当前串中的剩下的大于原本串的长度并且为‘bad’则加入\(*\),否则跳过\(*\)继续匹配,\(?\)是很好处理的。
最后只要判断两串是否都能跑完。复杂度\(O(n)\)
#include<bits/stdc++.h>
using namespace std;
char str1[30];
char str2[100005];
char str3[100005];
bool flag[30];
bool f = false;
bool check(int l);
int main(void)
{
memset(flag,0,sizeof(flag));
scanf("%s",str1);
scanf("%s",str2);
for(int i = 0; i < strlen(str1); i++)
flag[str1[i] - 'a']++;
int n;
scanf("%d",&n);
int l = strlen(str2);
for(int i = 0; i < l; i++)
if(str2[i] == '*')
f = true;
while(n--)
{
scanf("%s",str3);
if(check(l))
printf("YES\n");
else printf("NO\n");
}
return 0;
}
bool check(int l)
{
if(!f)
{
if(strlen(str3) != l)
return false;
}
else
{
if(strlen(str3) < l-1)
return false;
}
//printf("1\n");
int z = 0;
int k = strlen(str3);
//int ff = 0;
int i;
for( i = 0; i < l&&z < k+1;)
{
if(str2[i] == '*'&&k-l >= 0)
{ //printf("111\n");
while(!flag[str3[z]-'a']&&z < k&&l-i < k-z+1)
z++;
}
//printf("%d\n",z);
if(str2[i] == '*')
i++;
if(i >= l||z >= k+1)
break;
if(str2[i] == '?')
{
if(!flag[str3[z]-'a'])
return false;
else
{
i++,z++;
}
}
else
{
if(str2[i] != str3[z])
{
//printf("%d %d\n",i,z);
return false;
}
else i++,z++;
}
}
if(f&&(i < l||z < k))
{
return false;
}
return true;
}
B. Petya and Exam的更多相关文章
- CodeForces832-B. Petya and Exam
补的若干年以前的题目,水题,太菜啦_(:з」∠)_ B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...
- 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 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- Codefroces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- 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 ...
- 832B Petya and Exam
题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...
- CF832B Petya and Exam
思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...
随机推荐
- shell 的 功能语句--1
[1]说明性语句 (1)shell 程序和语句 shell 程序由零或多条shell语句构成. shell语句包括三类:说明性语句.功能性语句和结构性语句. 说明性语句: 以#号开始到该行结束,不被解 ...
- SCRDet——对小物体和旋转物体更具鲁棒性的模型
引言 明确提出了三个航拍图像领域内面对的挑战: 小物体:航拍图像经常包含很多复杂场景下的小物体. 密集:如交通工具和轮船类,在航拍图像中会很密集.这个DOTA数据集的发明者也提到在交通工具和轮船类的检 ...
- Vue3项目搭建规范
Vue3项目搭建规范 一. 代码规范 1.1 集成editorconfig配置 EditorConfig有助于为不同IDE编辑器上维护一致的编码风格 安装插件:EditorConfig for VS ...
- 商业创新不能等?用友低代码开发平台YonBuilder为您加速!
随着云计算.人工智能.物联网.大数据.5G等新一代技术的快速发展,越来越多的企业希望借助技术的力量加速数智化转型,期许通过更加敏捷和强大的应用系统推动企业的商业创新速度.但传统软件开发周期长.开发成本 ...
- 系列好文 | Kubernetes 弃用 Docker,我们该何去何从?
作者 | 张攀(豫哲) 来源 | 尔达 Erda 公众号 导读:Erda 作为一站式云原生 PaaS 平台,现已面向广大开发者完成 70w+ 核心代码全部开源!**在 Erda 开源的同时,我们计划编 ...
- A Child's History of England.6
It was a British Prince named Vortigern who took this resolution, and who made a treaty of friendshi ...
- 关于java中的安全管理器
最近再查看java的源码的时候看见了这一类代码 final SecurityManager sm = System.getSecurityManager(); 想要了解这个是为了做什么,查看资料之后发 ...
- @Data 注解引出的 lombok
今天在看代码的时候, 看到了这个注解, 之前都没有见过, 所以就查了下, 发现还是个不错的注解, 可以让代码更加简洁. 这个注解来自于 lombok,lombok 能够减少大量的模板代码,减少了在使用 ...
- Linux学习 - 网络命令
一.write 1 功能 给指定在线用户发信息,以Ctrl + D保存结束 2 语法 write <用户名> [信息] 二.wall(write all) 1 功能 给所有在线用户发送 ...
- spring mvc访问html页面404报错解决
<servlet> <servlet-name>context</servlet-name> <servlet-class>org.springfram ...