【CF 1023A】Single Wildcard Pattern Matching sbustr()函数

                         A. Single Wildcard Pattern Matching

You are given two strings ss and tt. The string ss consists of lowercase Latin letters and at most one wildcard character '*', the string tt consists only of lowercase Latin letters. The length of the string ss equals nn, the length of the string tt equals mm.

The wildcard character '*' in the string ss (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of ss can be replaced with anything. If it is possible to replace a wildcard character '*' in ss to obtain a string tt, then the string tt matches the pattern ss.

For example, if s=s="aba*aba" then the following strings match it "abaaba", "abacaba" and "abazzzaba", but the following strings do not match: "ababa", "abcaaba", "codeforces", "aba1aba", "aba?aba".

If the given string tt matches the given string ss, print "YES", otherwise print "NO".

Input

The first line contains two integers nn and mm (1≤n,m≤2⋅1051≤n,m≤2⋅105) — the length of the string ss and the length of the string tt, respectively.

The second line contains string ss of length nn, which consists of lowercase Latin letters and at most one wildcard character '*'.

The third line contains string tt of length mm, which consists only of lowercase Latin letters.

Output

Print "YES" (without quotes), if you can obtain the string tt from the string ss. Otherwise print "NO" (without quotes).

Examples

input

6 10
code*s
codeforces

output

YES

input

6 5
vk*cup
vkcup

output

YES

input

1 1
v
k

output

NO

input

9 6
gfgf*gfgf
gfgfgf

output

NO

题意:给出长度为n和m的两个字符串s,x.其中s内含有“*”字符,星号可以代替任何内容(包括空串),x与s相比除去星号代表的内容后如果相等,则输出YES。

substr()函数的介绍:https://blog.csdn.net/Xylon_/article/details/81532238

后台数据简直丧心病狂TAT

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define closeio std::ios::sync_with_stdio(false)

int main() 
{
	int n,m,i,len,flag=0;
	string s,x,s1,s2;
	cin>>n>>m;
	cin>>s>>x;
	for(i=0; i<n; i++)
		if(s[i]=='*')     //找到星号的位置
		{
			flag=1;
			break;
		}
	if(n-1>m)            //如果x串小于s串,必不可能相等

	{
		cout<<"NO"<<endl;
		return 0;
	}
	if(flag) 
	{
		s1=s.substr(0,i);
		s2=s.substr(i+1,n-i-1);
		//cout<<s1<<" "<<s2<<endl;
		len=s2.length();
		//cout<<x.substr(0,i)<<" "<<x.substr(m-len,m-1)<<endl;
		if(x.substr(0,i)==s1&&x.substr(m-len,m-i)==s2)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	else
	{
		if(s==x)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Xylon_/article/details/81806468