Codeforces Round #425 (Div. 2) - B
题目链接: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的更多相关文章
- Codeforces Round #425 (Div. 2)C
题目连接:http://codeforces.com/contest/832/problem/C C. Strange Radiation time limit per test 3 seconds ...
- Codeforces Round #425 (Div. 2)
A 题意:给你n根棍子,两个人每次拿m根你,你先拿,如果该谁拿的时候棍子数<m,这人就输,对手就赢,问你第一个拿的人能赢吗 代码: #include<stdio.h>#define ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 Round #425 (Div. 2))——A题&&B题&&D题
A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...
- 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 ...
- Codeforces Round #425 (Div. 2) C - Strange Radiation
地址:http://codeforces.com/contest/832/problem/C 题目: C. Strange Radiation time limit per test 3 second ...
随机推荐
- 一、Nginx常见问题
1.相同server_name多个虚拟主机优先级访问 最先读取哪个配置文件,就访问那个的网页 2.location匹配优先级 相同location,会被后面的覆盖 匹配优先级更高的,找后面的 = ...
- 前端每日实战:138# 视频演示如何用纯 CSS 创作一张 iPhone 价格信息图
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/OorLGZ 可交互视频 此视频是可 ...
- C/C++中动态内存分配
代码段:用来存放程序执行代码的一块内存区域.这部分内存大小在程序运行前已经知道,通常属于只读,其中包括只读的字符串常量,不可改变 BBS段:用来存放存放程序中未初始化的全局变量及静态变量,属于静态内存 ...
- 年薪100万的人都是怎么玩Excel的?
年薪100万的人都是怎么玩Excel的? 2017-12-21 13:42美国 作者:珍妮Jenny 来源:一周进步(ID:weekweekup) 本文已获原作者转载授权,如需转载请联系原公号 本文重 ...
- jmeter的日常特殊参数化
1.map转译符号: 如果///Mobile///:///18888888888/// 需要再参数化请这样做,////Mobile////://///${Mobile}///// 2.in ...
- 错误 error: The following untracked working tree files would be overwritten by merge:README.md
问题类型 相信很多小伙伴在创建新的git仓库后,会选上添加README.md文件,开始我也没太在意,应该也没有什么问题. 但是当我通过git添加远程仓库,给这个仓库上传代码时,出现了如下问题:erro ...
- fpython-笔记(五)装饰器、匿名函数
一.装饰器 装饰器,这个器就是函数的意思,连起来,就是装饰函数,装饰器本身也是一个函数,它的作用是用来给其他函数添加新功能,比如说,我以前写了很多代码,系统已经上线了,但是性能比较不好,现在想把程序里 ...
- C# 内存建表备忘
#region=====建表===== DataSet dataSet; // 创建表 DataTable table = new DataTable("testTable"); ...
- set_index()与reset_index()函数
一 set_index()函数 1 主要是理解drop和append参数,注意与reset_index()参数的不同. import pandas as pd df = pd.DataFrame({' ...
- UI自动化之js\jquery的应用
js\jquery的应用,有很多难以定位到的,可以通过js或者jquery来处理 目录 1.js 2.jquery 1.js 1.1js有5种定位,最后execute_script(js)来执行js ...