https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-425-Div-2-problem-B-Petya-and-Exam-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #425 (Div. 2), problem: (B) Petya and Exam Solution In C/C++

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s,t;
int q;
string str;
int w;
bool g[26];
int main()
{
cin>>s;
for(int i=0;i<s.size();i++)
{
g[s[i]-‘a’]=true;
}
cin>>t;
int lt=t.size();
int s=0;
w=-1;
for(int i=0;i<lt;i++)
{
if(t[i]==’*’)w=i;else s++;
}
scanf(“%d”,&q);
while(q–)
{
cin>>str;
int l=str.size();
if(l<s || (w==-1 && l!=s))
{
puts(“NO”);
continue;
}
int k=0;
bool f=true;
for(int i=0;i<l;i++)
{
if(k==w)
{
for(;i<w+(l-s);i++)
{
if(g[str[i]-‘a’])
{
f=false;
break;
}
}
i–;
}
else if(t[k]==’?’)
{
if(!g[str[i]-‘a’])
{
f=false;
break;
}
}
else
{
if(t[k]!=str[i])
{
f=false;
break;
}
}
if(!f)break;
k++;
}
if(f)puts(“YES”);else puts(“NO”);
}
return 0;
}

(Visited 50 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: