题意:给定两个串s与t,其中s可能有至多一个通配符*可以被当做任意长度与内容的串,问t能否与s匹配
n,m<=2e5
思路:
1 #include<cstdio> 2 #include<cstring> 3 #include<string> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<vector> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned int uint; 14 typedef unsigned long long ull; 15 typedef pair<int,int> PII; 16 typedef vector<int> VI; 17 #define fi first 18 #define se second 19 #define MP make_pair 20 #define N 210000 21 #define MOD 1000000007 22 #define eps 1e-8 23 #define pi acos(-1) 24 #define oo 2000000000 25 26 char s[N],t[N],c[N]; 27 28 int read() 29 { 30 int v=0,f=1; 31 char c=getchar(); 32 while(c<48||57<c) {if(c=='-') f=-1; c=getchar();} 33 while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar(); 34 return v*f; 35 } 36 37 void swap(int &x,int &y) 38 { 39 int t=x;x=y;y=t; 40 } 41 42 43 44 int main() 45 { 46 // freopen("1.in","r",stdin); 47 // freopen("1.out","w",stdout); 48 int n,m; 49 scanf("%d%d",&n,&m); 50 scanf("%s",s); 51 scanf("%s",t); 52 int flag=0; 53 int p=-1; 54 for(int i=0;i<=n-1;i++) 55 if(s[i]=='*'){flag=1; p=i; break;} 56 // printf("%d ",flag); 57 if(!flag) 58 { 59 int ans=1; 60 if(n!=m) ans=0; 61 for(int i=0;i<=n-1;i++) 62 if(s[i]!=t[i]){ans=0; break;} 63 if(ans) printf("YES "); 64 else printf("NO "); 65 } 66 else 67 { 68 int flag1=1; 69 for(int i=0;i<=p-1;i++) 70 if(s[i]!=t[i]){flag1=0; break;} 71 int flag2=1; 72 int k=m-1; 73 for(int i=n-1;i>=p+1;i--) 74 { 75 if(s[i]!=t[k]){flag2=0; break;} 76 k--; 77 } 78 if(n-1<=m&&flag1+flag2==2) printf("YES "); 79 else printf("NO "); 80 } 81 82 return 0; 83 }