Codeforces Round #425 (Div. 2) B - Petya and Exam
地址:http://codeforces.com/contest/832/problem/B
题目:
2 seconds
256 megabytes
standard input
standard output
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.
Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.
Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.
A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.
The good letters are given to Petya. All the others are bad.
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.
The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*" occurs in s no more than once.
The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings.
n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.
It is guaranteed that the total length of all query strings is not greater than 105.
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary.
- ab
a?a
2
aaa
aab
- YES
NO
- abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax
- NO
YES
NO
YES
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.
Explanation of the second example.
- The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.
- The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.
- The third query: "NO", because characters "?" can't be replaced with bad letters.
- The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
思路:
暴力匹配,但是这题细节多。。。。
- #include <bits/stdc++.h>
- using namespace std;
- #define MP make_pair
- #define PB push_back
- typedef long long LL;
- typedef pair<int,int> PII;
- const double eps=1e-;
- const double pi=acos(-1.0);
- const int K=1e6+;
- const int mod=1e9+;
- char gd[],sa[K],sb[K];
- int main(void)
- {
- int n,la,lb,ok=;
- scanf("%s%s%d",sb+,sa+,&n);
- for(int i=;sb[i];i++) gd[sb[i]]=;
- for(int i=;sa[i];i++) if(sa[i]=='*') ok=;
- la=strlen(sa+);
- while(n--)
- {
- scanf("%s",sb+);
- lb=strlen(sb+);
- int ff=,i,j;
- if((la==lb+&&!ok)||la>lb+) ff=;
- if(!ok && la<lb) ff=;
- for(i=,j=;i<=la&&j<=lb&&ff;i++,j++)
- if(sa[i]==sb[j]||(sa[i]=='?'&&gd[sb[j]])) ;
- else if(sa[i]=='*')
- {
- for(int k=;k<=lb-la&&ff;k++,j++)
- if(gd[sb[j]]) ff=;
- j--;
- }
- else ff=;
- if(ff) printf("YES\n");
- else printf("NO\n");
- }
- return ;
- }
Codeforces Round #425 (Div. 2) B - Petya and Exam的更多相关文章
- 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) 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) B】Petya and Exam
[Link]:http://codeforces.com/contest/832/problem/B [Description] *能代替一个字符串(由坏字母组成); ?能代替单个字符(由好字母组成) ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(树状数组)
D. Petya and Array 题目链接:https://codeforces.com/contest/1042/problem/D 题意: 给出n个数,问一共有多少个区间,满足区间和小于t. ...
- 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 ...
随机推荐
- SQL在oracle和SQLserver将查询结果创建为新表的不同之处
------在SQL中,将查询的结果创建为新表是如下这样的 select distinct t1.column1,.t2.column2 into table3 from table1.t1 join ...
- [转]ODBC编程指南
DM4 ODBC编程指南本章结合DM4数据库的特点,比较全面系统的介绍ODBC的基本概念以及DM4 ODBC DRIVER的使用方法,以便用户更好地使用DM4 ODBC编写应用程序.ODBC提供给你访 ...
- 一个格式化字符串的函数ToString
A Formatting String Function 原文:http://flounder.com/tostring.htm CString ToString(LPCTSTR fmt, ...) ...
- python3----requests
import requests def get_html_text(url): try: r = requests.get(url, timeout=30) r.raise_for_status() ...
- 阿里云CentOS6.8云服务器配置安全组规则
前提:已经购买阿里云服务器,域名解析也完成了 需要对安全组规则进行配置,才能进行访问 1.进入阿里云首页https://www.aliyun.com/,如下图 2.进入控制台首页,如下图 3.在上图页 ...
- c++11 lambda(了解)
this->send_change_equip = ([this](ChangeEquipPT channge) { send_cmd(s2c_change_equip, &channg ...
- java基础---->string字面量的使用
这里简单的理解一下java中关于string字面量的知识,关于字节码可以使用java自带的javap工具查看. string字面量 一.直接贴出测试的代码 A string literal alway ...
- 简单深搜:POJ1546——Sum it up
结束了三分搜索的旅程 我开始迈入深搜的大坑.. 首先是一道比较基础的深搜题目(还是很难理解好么) POJ 1564 SUM IT UP 大体上的思路无非是通过深搜来进行穷举.匹配 为了能更好地理解深搜 ...
- Linux安装好系统后优化
author:headsen chen date: 2018-05-14 15:35:49 1.快速更改国内yum源 mv /etc/yum.repos.d/CentOS-Base.repo /etc ...
- panzer 电力项目十一--hibernate操作大文本字段Blob和Clob
hibernate操作大文本字段Blob和Clob解决方案: 1.大文本字段Blob和Clob(流); 2.截串存取 第一步: 创建新表:Elec_CommonMsg_Content create t ...