题目链接:http://codeforces.com/contest/832/problem/B

题意:给定一个好字母集合(只有小写字母,除了这些外其余都是坏字母集合),给定一个匹配模式串,

模式串只包含小写字母,'*','?'; 其中'?'可以替换成“好字母集合”中的任意一个字母

‘*’可以替换成空字符串坏字母组成的字符串

然后给你n个字符串,问你这n个字符串哪些满足给定的匹配模式。

思路:按照题意模拟,或者直接写个正则表达式来匹配即可。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
using namespace std;
typedef long long int LL;
const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
char gchar[], pattern[MAXN], str[MAXN];
int vis[];
int main(){
#ifdef kirito
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n, slen, plen, glen;
while (~scanf("%s", gchar)){
scanf("%s", pattern); scanf("%d", &n);
plen = strlen(pattern); glen = strlen(gchar);
bool flag = false;
for (int i = ; i < plen; i++){
if (pattern[i] == '*'){
flag = true; break;
}
}
memset(vis, , sizeof(vis));
for (int i = ; i < glen; i++){
vis[gchar[i] - 'a'] = ;
}
for (int i = , j, k; i <= n; i++){
scanf("%s", str);
slen = strlen(str);
bool res = true;
if (plen - == slen&&flag){
int pos = ;
for (j = ; j < slen&&res; j++, pos++){
if (pattern[pos] == '*'){ //换成空字符串
j--;
}
else if (pattern[pos] == '?'){
if (!vis[str[j] - 'a']){
res = false;
}
}
else{
if (pattern[pos] != str[j]){
res = false;
}
}
}
}
else if (plen <= slen){
int pos = , pslen = slen - plen;
if (pslen&&!flag){
res = false;
}
for (j = ; j < slen&&res; j++, pos++){
if (pattern[pos] == '*'){ //换成坏字母组成的字符串
for (k = j; k <= j + pslen; k++){
if (vis[str[k] - 'a']){
res = false; break;
}
}
j = j + pslen;
}
else if (pattern[pos] == '?'){
if (!vis[str[j] - 'a']){
res = false;
}
}
else{
if (pattern[pos] != str[j]){
res = false;
}
}
}
}
else{
res = false;
}
printf(res ? "YES\n" : "NO\n");
}
}
return ;
}

Codeforces Round #425 (Div. 2) - B的更多相关文章

  1. Codeforces Round #425 (Div. 2)C

    题目连接:http://codeforces.com/contest/832/problem/C C. Strange Radiation time limit per test 3 seconds ...

  2. Codeforces Round #425 (Div. 2)

    A 题意:给你n根棍子,两个人每次拿m根你,你先拿,如果该谁拿的时候棍子数<m,这人就输,对手就赢,问你第一个拿的人能赢吗 代码: #include<stdio.h>#define ...

  3. Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组

    Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations ...

  4. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

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

  6. Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)

    It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day h ...

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

  8. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

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

  10. Codeforces Round #425 (Div. 2) C - Strange Radiation

    地址:http://codeforces.com/contest/832/problem/C 题目: C. Strange Radiation time limit per test 3 second ...

随机推荐

  1. D. Shortest Cycle

    D. Shortest Cycle A[i]&A[j]!=0连边, 求图中最小环 N>128 时必有3环 其他暴力跑 folyd最小环 #include<bits/stdc++.h ...

  2. Java 统计单词频数

    输出单个文件中的 N 个英语单词出现的次数 定义双列集合,将单词不重复的读入一列中,另一列用来计数 import java.io.BufferedReader; import java.util.Ar ...

  3. [CSP-S模拟测试]:毛一琛(meet in the middle)

    题目描述 历史学考后,$MYC$和$ztr$对答案,发现选择题他们没有一道选的是一样的.最后他们都考了个$C$.现在问题来了,假设他们五五开,分数恰好一样(问答题分数也恰好一样,只考虑选择题).已知考 ...

  4. CTO爆料:2019程序员最需要了解的行业前沿技术是什么?

    安森,个推CTO 毕业于浙江大学,现全面负责个推技术选型.研发创新.运维管理等工作,已带领团队开发出针对移动互联网.金融风控等行业的多项前沿数据智能解决方案. 曾任MSN中国首席架构师,拥有十余年资深 ...

  5. linux管理权限

    1.linux命令查询 root id 2.切换用户 su - xiaobai 一定要加"  -  "这个会将你的所有环境变量都带过来 3.root用户切换普通用户不需要输入密码反 ...

  6. Python selenium 三种等待方式详解(必会)

    很多人在群里问,这个下拉框定位不到.那个弹出框定位不到…各种定位不到,其实大多数情况下就是两种问题:1 有frame,2 没有加等待.殊不知,你的代码运行速度是什么量级的,而浏览器加载渲染速度又是什么 ...

  7. EDM营销应注意要定期发送邮件

    一个成熟的EDM营销方案应该要确定完整的邮件发送频率,并且严格按照计划执行.这点在EDM营销过程中非常重要,下面为大家分析一下. 一个EDM营销应该确定一下发送的时间,每月或者每周发送一次,这样用户能 ...

  8. 用Vue来实现音乐播放器(十七):歌手页右侧快速入口实现

    快速入口的列表是其实是之前处理的歌手的数据中的关于title的列表 shorcutList属性是计算属性   通过ret数组中的title计算到的 所以我们要在singer.vue组件中将数据传入到l ...

  9. dict用法

    1 dict.items() https://www.runoob.com/python3/python3-att-dictionary-items.html 2 setdefault的用法 注意se ...

  10. 解决浏览器打开网页后提示“dns_probe_possible”的方法

    使用浏览器浏览网页时偶尔会遇到无法上网且浏览器提示:DNS_PROBE_POSSIBLE 一般有三种情况会导致这样的故障: 1.网络协议出现故障,也就是常说的 DNS 设置问题 2.浏览器中设置问题, ...