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的更多相关文章

  1. CodeForces832-B. Petya and Exam

    补的若干年以前的题目,水题,太菜啦_(:з」∠)_    B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...

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

  3. CodeForces 832B Petya and Exam

    B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

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

  5. Codefroces 832B Petya and Exam

    B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. E - Petya and Exam CodeForces - 832B 字典树+搜索

    E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...

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

  8. 832B Petya and Exam

    题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...

  9. CF832B Petya and Exam

    思路: 模拟. 实现: #include <iostream> using namespace std; string a, b; ]; bool solve() { ) return f ...

随机推荐

  1. 47-Generate Parentheses

    Generate Parentheses My Submissions QuestionEditorial Solution Total Accepted: 86957 Total Submissio ...

  2. 【模板】网络最大流(EK、Dinic、ISAP)(网络流)/洛谷P3376

    题目链接 https://www.luogu.com.cn/problem/P3376 题目大意 输入格式 第一行包含四个正整数 \(n,m,s,t\),分别表示点的个数.有向边的个数.源点序号.汇点 ...

  3. 【模板】无源汇有上下界可行流(网络流)/ZOJ2314

    先导知识 网络最大流 题目链接 https://vjudge.net/problem/ZOJ-2314 题目大意 多组数据,第一行为数据组数 \(T\). 对于每一组数据,第一行为 \(n,m\) 表 ...

  4. 【Redis】过期键删除策略和内存淘汰策略

    Redis 过期键策略和内存淘汰策略 目录 Redis 过期键策略和内存淘汰策略 设置Redis键过期时间 Redis过期时间的判定 过期键删除策略 定时删除 惰性删除 定期删除 Redis过期删除策 ...

  5. MapReduce02 序列化

    目录 MapReduce 序列化 概述 自定义序列化 常用数据序列化类型 int与IntWritable转化 Text与String 序列化读写方法 自定义bean对象实现序列化接口(Writable ...

  6. 紧张 + 刺激,源自一次 OOM 历险

    作者 | 蚂蝗 背景 ​ Erda 是集 DevOps.微服务治理.多云管理以及快数据管理等多功能的开源一站式企业数字化平台.其中,在 DevOps 模块中,不仅有 CI/CD.项目协同等功能,同时还 ...

  7. maven常用Java配置

    maven国内镜像 ------------------------------------------------------------------------------------------ ...

  8. react中在hooks方法useEffect中加载异步数据

    useEffect( ()=>{ (async function getPipeList(value:any) { let result= await GetPipeList(value); s ...

  9. 【JavaWeb】【Eclipse】使用Eclipse创建我的第一个网页

    使用Eclipse创建我的第一个网页 哔哩哔哩 萌狼蓝天 你可以直接点击Finish,也可以点击Next,到下面这个界面后,勾选生成web.xml然后Finish(你不这样做就会没有Web.xml文件 ...

  10. Nginx区分PC和手机

    目录 一.简介 二.配置 nginx识别手机端跳转到wap pc端跳转移动端 一.简介 有时候需要当手机访问PC站页面时自动跳转到对应的手机站页面. 二.配置 nginx识别手机端跳转到wap 即手机 ...