Codeforces Round #425 (Div. 2) B. Petya and Exam (string processing)

Source: Internet
Author: User
Tags lowercase strlen time limit
B. Petya and Exam time limit per test 2 seconds memory limit per test megabytes input standard input output standard o Utput

It ' s hard times now. Today Petya needs to score the 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 中文版 letters, characters "?" and "*"). It is known this character "*" occurs no more than once in the pattern.

Also, n query strings is given, it's required to determine for each of the them if the pattern matches it or not.

Everything seemed easy to Petya, and then he discovered that the special pattern characters differ from their usual meanin G.

A pattern matches a string if it is possible to replace each character "?" with one good lowercase 中文版, and the Character "*" (if there is one) with any, including empty, string of bad lowercase Chinese letters, so, the resulting String is the same as the given string.

The good letters is given to Petya. All the others is bad. Input

The first line contains a string with length from 1 to consisting of distinct lowercase 中文 letters. These letters is good letters, all the others is bad.

The second line contains the PATTERN-A string s of lowercase 中文版 letters, characters "?" and "*" (1≤|s|≤105). It is guaranteed this 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 the them contains single non-empty string consisting of lowercase Chinese letters-a query string.

It is guaranteed, the total length of all query strings are not greater than 105. Output

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

AB
a?a
2
AAA
AAB
Output
YES
NO
Input
ABC
a?a?a*
4
abacaba
abaca
Apapa
Aaaaax
Output
No
Yes
no
Yes
Note

In the first example we can replace '? ' with good letters ' a ' and ' B ', so we can see that the answer for the first query I S "YES", and the answer for the second query are "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-to match The query string is to replace it with the string "Ba", in which both letters is good. The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" Can is Replaced with empty string, and the strings would 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 W ith a string of bad letters "x".

Test instructions: The question mark can be replaced by any good letter, the asterisk can only be replaced by one or more bad letters or empty, ask whether there is a correct result. Test instructions is simple, look directly at the code for string processing.

#include <bits/stdc++.h> #define EPS 1e-9 #define PI 3.141592653589793 #define BS 1000000007 #define Bsize #defin
e MEM (a) memset (A,0,sizeof (a)) typedef long Long LL;
using namespace Std;
String Ch,yuan;
Char q[100005],s[100005];
int book[200];
	int cmp (char C,char C2) {if (C==C2) return 1; if (c== '? ')
	&AMP;&AMP;BOOK[C2]) return 1;
return 0;
	} int main () {int i,k,j,n,len,len1;
	cin>>ch;
	For (I=0;i<ch.size (); i++) book[ch[i]]=1;
	scanf ("%s%d", s,&n);
	Len=strlen (s);
		for (i=0;i<n;i++) {int flog=1;
		int now=0;
		GetChar ();
		scanf ("%s", q);
		Len1=strlen (q);
		if (len1<len-1) flog=0;
					else {for (k=0;k<len;k++) {if (s[k]== ' * ') {if (len1==len-1) continue;
					else {for (j=0;j<=len1-len;now++,j++) if (Book[q[now]]) flog=0;
						}} else {if (!cmp (S[k],q[now])) {flog=0;	
					Break
				} now++;
		}} if (Now!=len1) flog=0; } if (flog) cout<< "YES"<<endl;
	else cout<< "NO" <<endl;
 } return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.