题目链接: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. CF889E Mod Mod Mod

    http://codeforces.com/problemset/problem/889/E 题解 首先我们观察到在每次取模的过程中一定会有一次的结果是\(a_i-1\),因为如果不是,我们可以调整, ...

  2. Linux相关基础知识

    文件目录 /bin 放置系统执行档的目录,指令可被root与一般账户所使用. /boot 放置开机使用到的文档,包括linux核心档案,开机选单与所需设定档. /dev 任何装置与周边设备都是以档案的 ...

  3. 前端开发学习笔记 - 1. Node.JS安装笔记

    Node.JS安装笔记 Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an ...

  4. oracle各服务说明及cmd启动启动命令

    成功安装Oracle 11g后,共有7个服务,一.这七个服务的含义分别为:1. Oracle ORCL VSS Writer Service:Oracle卷映射拷贝写入服务,VSS(Volume Sh ...

  5. ConcurrentLinkedQueue 源码分析

    ConcurrentLinkedQueue ConcurrentLinkedQueue 能解决什么问题?什么时候使用 ConcurrentLinkedQueue? 1)ConcurrentLinked ...

  6. centos输入正确的账号和密码登陆不进去

    vm下启动centos,输入正确的账号和密码,依然登陆不进去,一直处于这个界面: 暂时的解决方法是:先等待一段时间.重启,然后再输入密码,然后,ctrl+c 不停地ctrl+c,然后就登陆进去了.什么 ...

  7. Java 位运算超全面总结

    1.原码.反码.补码 关于原码.反码.补码的相关知识作者不打算在这里长篇大论,相关知识已有别的大佬总结很好了,还请老铁自行 Google,不过有篇知乎回答是作者学编程以来见过对相关知识最通俗易懂,生动 ...

  8. Tensorflow创建和读取17flowers数据集

    http://blog.csdn.net/sinat_16823063/article/details/53946549 Tensorflow创建和读取17flowers数据集 标签: tensorf ...

  9. ETCD分布式锁实现选主机制(Golang实现)

    ETCD分布式锁实现选主机制(Golang) 为什么要写这篇文章 做架构的时候,涉及到系统的一个功能,有一个服务必须在指定的节点执行,并且需要有个节点来做任务分发,想了半天,那就搞个主节点做这事呗,所 ...

  10. [转载]借助openssl解析ECC公钥

    void GetPubKey(const char* FilePath, char* PubKey) { unsigned ]; unsigned char *pTmp = NULL; FILE *f ...