【Codeforces Round #425 (Div. 2) B】Petya and Exam
and Codeforces div round
2023-09-14 09:03:50 时间
*能代替一个字符串(由坏字母组成);
?能代替单个字符(由好字母组成);
问你每个串能不能被匹配
对于没有*的情况;
先判断长度是否相同,不相同则不行;
否则看看问号所在的位置是不是?且,看看?对应的字母是不是好字母;
对于有*的情况;
先把左边和右边的字符和母串的对应位置对应起来;
左对齐比较和右对齐比较
然后中间部分就是用坏字母组成的字符串了;
对于母串的长度小于等于匹配串长度-2的直接输出无解;
对于母串长度等于匹配串长度-1的,除非匹配串里有*,否则直接输出无解;
1
对于特殊情况;
还是分类讨论的方法比较好;
不然可能有意想不到的错误;
就比如这题;
我漏掉了长度不能相同;
而在长度不同的情况下对没有*的母串进行了匹配;
#include <bits/stdc++.h>
#define LL long long
using namespace std;
string s,ts;
int good[300],len,fi=-1,Q;
bool get_ans(){
if ((int) ts.size()<= (int) s.size()-2) return false;
if ((int) ts.size()== (int) s.size()-1 && fi==-1) return false;
if (fi==-1 && (int) ts.size()!=(int)s.size()) return false;
int l = 0,r = ts.size()-1;
for (int i = 0;i <= fi-1;i++){
if (s[i]!=ts[l]) {
if (s[i]!='?')
return false;
else
if (!good[ts[l]])
return false;
}
l++;
}
for (int i = len-1;i >=fi+1;i--){
if (s[i]!=ts[r]){
if (s[i]!='?')
return false;
else
if (!good[ts[r]])
return false;
}
r--;
}
for (int i = l;i <= r;i++)
if (good[ts[i]]) return false;
return true;
}
int main(){
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio();
cin >> s;
len = s.size();
for (int i = 0;i <= len-1;i++)
good[s[i]] = 1;
cin >> s;
len = s.size();
for (int i = 0;i <= len-1;i++)
if (s[i]=='*')
fi = i;
scanf("%d",&Q);
for (int i = 1;i <= Q;i++){
cin >> ts;
int ok = false;
if (get_ans()){
cout <<"YES"<<endl;
continue;
}
cout<<"NO"<<endl;
}
return 0;
}
相关文章
- mybatis异常invalid comparison: java.util.Date and java.lang.String
- 【阅读笔记】低照度图像增强-《Adaptive and integrated neighborhood-dependent approach for nonlinear enhancement of
- 【算法竞赛 - 搜索】Black And White
- R语言代做编程辅导Big Data Analytics: Assignment – Hurricane Sandy and Flickr(附答案)
- Kibana报错 Privileges are missing and can't be removed, currently
- ORA-01879: the hh25 field must be between 0 and 24 ORACLE 报错 故障修复 远程处理
- ORA-19728: data object number conflict between table string and partition string in table string ORACLE 报错 故障修复 远程处理
- ORA-23370: table string and table string are not shape equivalent (string) ORACLE 报错 故障修复 远程处理
- ORA-23633: Cannot turn off combined capture and apply mode in apply-state checkpoint mode (value “string”, string parameter string) ORACLE 报错 故障修复 远程处理
- ORA-24430: Null values for sqltext and key were specified. ORACLE 报错 故障修复 远程处理
- ORA-26810: Apply “string” on database “string” is in the mode of combined capture and apply. ORACLE 报错 故障修复 远程处理
- ORA-39322: Cannot use transportable tablespace with TIMESTAMP WITH TIME ZONE columns and different time zone version. ORACLE 报错 故障修复 远程处理
- ORA-01378: The logical block size (string) of file string is not compatible with the disk sector size (media sector size is string and host sector size is string) ORACLE 报错 故障修复 远程处理
- ORA-09704: sstascre: ftok error in creating test and set pages. ORACLE 报错 故障修复 远程处理
- Codeforces 842B Gleb And Pizza几何,水详解编程语言
- Codeforces 842A Kirill And The Game暴力,水详解编程语言
- MySQL and RADIUS: Unlocking Database Power(mysqlradius)
- 多条件查询MySQL中使用And多条件查询的步骤(mysql中and)
- and命令Linux系统下Expand命令简介(linux下exp)
- Exploring the Versatility and Functionality of Linux SUSE10: A Comprehensive Guide(linuxsuse10)
- Exploring the Benefits and Challenges of NW336 Linux for Advanced Computing(nw336linux)
- MySQL中的rand函数Note: This is a title and not an article. It is within the word limit of 25 characters.(mysql的rand)
- MySQL中AND的使用方法解析(mysql中and的用法)
- MySQL中AND的使用方法及含义解析(mysql中and的含义)