1023ASingle Wildcard Pattern Matching

A. Single Wildcard Pattern Matching

http://codeforces.com/problemset/problem/1023/A

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

Note

In the first example a wildcard character '*' can be replaced with a string "force". So the string ss after this replacement is "codeforces" and the answer is "YES".

In the second example a wildcard character '*' can be replaced with an empty string. So the string ss after this replacement is "vkcup" and the answer is "YES".

There is no wildcard character '*' in the third example and the strings "v" and "k" are different so the answer is "NO".

In the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string tt so the answer is "NO".

 

题意:两个字符串s,t。若把s中的*删除或替换成一些序列,能使之变成t输出"YES",否则,输出"NO"。

思路:把情况找全就行。

代码:

#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#define inf 0x3f3f3f3f
using namespace std;

char s[200005];
char t[200005];

int main()
{
    int n,m;
    cin>>n>>m;
    cin>>s>>t;
    int h=-1;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='*')
        {
            h=i;
            break;
        }
    }
    if(h==-1)
    {
        if(n!=m)
            cout<<"NO"<<endl;
        else
        {
            int flag2=0;
            for(int i=0;i<n;i++)
            {
                if(s[i]!=t[i])
                {
                    flag2=1;
                    break;
                }
            }
            if(flag2)
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
        }
    }
    else if(h!=-1&&n-1>m)
        cout<<"NO"<<endl;
    else
    {
        int flag=0;
        for(int i=0;i<h;i++)
        {
            if(s[i]!=t[i])
            {
                flag=1;
                break;
            }
        }
        if(flag)
            cout<<"NO"<<endl;
        else
        {
            int j=m-1;
            int flag1=0;
            for(int i=n-1;i>h;i--)
            {
                if(s[i]!=t[j])
                {
                    flag1=1;
                    break;
                }
                j--;
            }
            if(flag1)
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值