Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

时间:2021-10-08 06:57:58

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

A. Single Wildcard Pattern Matching

题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * "。

代码:

 //A
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=*1e5+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); char s[maxn],t[maxn]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
scanf("%s%s",s,t);
int pos=-;
for(int i=;i<n;i++){
if(s[i]=='*'){
pos=i;
break;
}
}
if(pos==-){
if(n!=m)
cout<<"NO"<<endl;
else{
for(int i=;i<n;i++){
if(s[i]!=t[i]){
cout<<"NO"<<endl;
return ;
}
}
cout<<"YES"<<endl;
}
}
else{
if(m<n-){
cout<<"NO"<<endl;
return ;
}
for(int i=;i<pos;i++){
if(s[i]!=t[i]){
cout<<"NO"<<endl;
return ;
}
}
for(int i=n-,j=m-;i>pos;i--,j--){
if(s[i]!=t[j]){
cout<<"NO"<<endl;
return ;
}
}
cout<<"YES"<<endl;
}
}