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 ...
随机推荐
- php开发常用技巧总结
1.[本地开启xdebug导致执行时间超max_execution_time产生的问题处理方法]xdebug开启,会导php执行速度慢,超max_execution_time,这种情况下有必要合理设置 ...
- [CSP-S模拟测试]:毛二琛(DP)
题目描述 $MYC$在$NOI2018$中,遇到了$day1T2$这样一个题,题目是让你求有多少“好”的排列.$MYC$此题没有获得高分,感到非常惭愧,于是回去专心研究排列了.如今数排列的题对$MYC ...
- 双边滤波Matlab代码
%简单地说: %A为给定图像,归一化到[,]的矩阵 %W为双边滤波器(核)的边长/ %定义域方差σd记为SIGMA(),值域方差σr记为SIGMA() %%%%%%%%%%%%%%%%%%%%%%%% ...
- 微信小程序image组件
image组件:是小程序专门针对图片的组件,功能强大 image组件的属性: src:类型 字符串 图片资源的路径 mode:类型 字符串 图片裁剪缩放模式 lazy-load:类型 布尔 图片的懒加 ...
- React-Native 之 GD (七)下拉刷新 及 上拉加载更多
1.下拉刷新 使用第三方插件 下载插件: $ npm install react-native-pull@latest --save 引入: import {PullList} from 'reac ...
- 查看Linux中lanmp的各软件编译参数
转载 如何查看已经安装的nginx.apache.mysql和php的编译参数 Mysql查看mysql编译参数 Mysql5.4及之前版本查看编译安装参数,进入到mysql安装目录的bin下面 $ ...
- qbzt day4 下午
有向图的强连通分量 强联通:两个点之间可以互相到达 如果某个图任意两个点都是强联通的,那么称这个图强联通 如果一个图的子图是强联通的,那么称这个图是强联通子图 一个图的极大强联通子图被称作强连通分量 ...
- C# winform 键盘全局事件
本文转载自:http://www.cnblogs.com/yukaizhao/archive/2010/12/14/winform_keyup.html 在winform程序中给form添加了keyu ...
- 红帽虚拟化RHEV-PXE批量安装RHEV-H
目录 目录 前言 软件环境 前提 部署 PXE 环境 使用 yum 安装所需软件 配置 DHCP 配置 TFTP-Server 配置 vsftpd 服务用于提供安装系统所需软件包 安装 kicksta ...
- source ~/.bash_profile是什么意思
~ 这个符号表示你的家目录,.bash_profile 是一个隐藏文件,主要是用来配置bash shell的,source -/.bash_profile 就是让这个配置文件在修改后立即生效.