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;
}

#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;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Trump lays out the pomp for Xi but says little about the significant tensions in US-China relations

A Grand Diplomatic Spectacle Amid Underlying Geopolitics In a high-profile diplomatic engagement that blended elaborate ceremonial fanfare with cautious statecraft, Donald Trump welcomed Chinese President...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

There comes a point when you realise that tolerating a frustrating situation is costing you more than just fixing it properly. That was the...

Ideas on modernizing the open-source desktop

For decades, the Linux community has delivered unparalleled stability, modularity, and power. However, user experience and interface design often lag behind proprietary alternatives. Veteran...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!