当前位置: 代码迷 >> 综合 >> Codeforces Round #504 1023A - Single Wildcard Pattern Matching
  详细解决方案

Codeforces Round #504 1023A - Single Wildcard Pattern Matching

热度:65   发布时间:2023-11-08 15:36:28.0

题意:输入两个字符串,字符串里面可能有一个通配符,可以匹配任意小写英文字母,也可以匹配空字符,现在判断能不能把第一个字符串,改成第二个字符串。能YES,否则No。
写的好丑。。。

#include<bits/stdc++.h>
#define maxn 300010
using namespace std;
typedef long long ll;
ll n,m,pos;
char s1[maxn],s2[maxn];
int main(){std::ios::sync_with_stdio(false);cin>>n>>m;// getchar();cin>>s1>>s2;if(n>m+1){cout<<"NO"<<endl;return 0;}int pos=-1;for(int i=0;i<n;i++){if(s1[i]=='*'){pos=i;break;}}if(pos==-1){if(n!=m) {
   cout<<"NO"<<endl; return 0;}for(int i=0;i<n;i++){if(s1[i]!=s2[i]){cout<<"NO"<<endl;return 0;}}cout<<"YES"<<endl;}else{//deal with frontfor(int i=0;i<pos;i++){if(s1[i]!=s2[i]) {
   cout<<"NO"<<endl;return 0;}}//deal with backint cur=-2;char ch=s1[pos+1];if(pos==n-1){cout<<"YES"<<endl;}else{for(int i=n-1,j=m-1;i>=pos+1;i--,j--){if(s1[i]!=s2[j]){ cout<<"NO"<<endl; return 0;}}cout<<"YES"<<endl;}}return 0;
}
  相关解决方案