题意:给定两个串s与t,其中s可能有至多一个通配符*可以被当做任意长度与内容的串,问t能否与s匹配

n,m<=2e5

思路:

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 210000
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
#define oo 2000000000 char s[N],t[N],c[N]; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void swap(int &x,int &y)
{
int t=x;x=y;y=t;
} int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
scanf("%s",s);
scanf("%s",t);
int flag=;
int p=-;
for(int i=;i<=n-;i++)
if(s[i]=='*'){flag=; p=i; break;}
// printf("%d\n",flag);
if(!flag)
{
int ans=;
if(n!=m) ans=;
for(int i=;i<=n-;i++)
if(s[i]!=t[i]){ans=; break;}
if(ans) printf("YES\n");
else printf("NO\n");
}
else
{
int flag1=;
for(int i=;i<=p-;i++)
if(s[i]!=t[i]){flag1=; break;}
int flag2=;
int k=m-;
for(int i=n-;i>=p+;i--)
{
if(s[i]!=t[k]){flag2=; break;}
k--;
}
if(n-<=m&&flag1+flag2==) printf("YES\n");
else printf("NO\n");
} return ;
}

【CF1023A】Single Wildcard Pattern Matching(模拟)的更多相关文章

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

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

  2. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-A-Single Wildcard Pattern Matching

    #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> ...

  3. Beginning Scala study note(5) Pattern Matching

    The basic functional cornerstones of Scala: immutable data types, passing of functions as parameters ...

  4. A Simple C++ Template Class that Matches a String to a Wildcard Pattern

    A recently implemented enhanced wildcard string matcher, features of which including, Supporting wil ...

  5. Symbols of String Pattern Matching

    Symbols of String Pattern Matching in Introduction to Algorithms. As it's important to be clear when ...

  6. scala pattern matching

    scala语言的一大重要特性之一就是模式匹配.在我看来,这个怎么看都很像java语言中的switch语句,但是,这个仅仅只是像(因为有case关键字),他们毕竟是不同的东西,switch在java中, ...

  7. Zhu-Takaoka Two-dimensional Pattern Matching

    Two dimensional pattern matching. Details may be added later.... Corresponding more work can be foun ...

  8. [PureScript] Break up Expressions into Cases in PureScript using Simple Pattern Matching

    Pattern matching in functional programming languages is a way to break up expressions into individua ...

  9. [学习笔记]编译sensetime发表的Single View Stereo Matching(SVS)遇到的问题

    最近在研究用深度学习预测图像深度信息的方法,一开始用的是2017年CVPR上Godard大神的monodepth,代码在这里.这篇文章介绍了利用双目的consistency训练网络以对单张图像进行深度 ...

随机推荐

  1. ssh整合思想初步 structs2 Spring Hibernate三大框架各自要点

    Web层用Structs2的action Service层用Spring的IoC和aop以及JdbcTemplate或者Transaction事务(创建对象及维护对象间的关系) Dao层用Hibern ...

  2. libnet TCP示例

    [root@TD18 tmp]#gcc -o .c -lnet [root@TD18 tmp]#./ please enter Host address 11.11.11.11 please ente ...

  3. 数组char a[4] 保存了一个数据,怎么转换为unsigned int呢 ?

    [待解决问题] 浏览: 701次 注意char并不表示字符的 a[0]=0; a[1]=0; a[2]=3; a[3]=0; 那么我要的unsigned int b应该等于: b= 0x0000030 ...

  4. Unity3d 判断物体是否在可见范围内

    unity中自带两个回调函数: void OnBecameVisible()//当物体可见时,回调一次. void OnBecameInvisible()//当物体不可见时,回调一次. 在untiy编 ...

  5. MySQL中CONCAT()的用法

    MySQL中CONCAT()的用法 在日常开发过程中,特别是在书写接口的时候,经常会遇到字符串拼接的情况,比如在返回图片数据时,数据库里往往存储的是相对路径,而接口里一般是存放绝对地址,这就需要字符串 ...

  6. windows server2008R2 64位 配置 mysql-8.0.15-winx64

    下载mysql: 1 https://dev.mysql.com/downloads/mysql/ 如图: 然后在解压的文件夹里面新建 my.ini文件,内容如下 按 Ctrl+C 复制代码 按 Ct ...

  7. 【php】instanceof

    instanceof 的使用还有一些陷阱必须了解.在 PHP 5.1.0 之前,如果要检查的类名称不存在,instanceof 会调用__autoload().另外,如果该类没有被装载则会产生一个致命 ...

  8. 20.Yii2.0框架多表关联一对多查询之hasMany

    目录 新手模式 hasMany关联模式查询 新建mode层Article.php 新建mode层Category.php 新建控制器HomeController.php 新手模式 用上次的查询结果,作 ...

  9. atag信息处理

    machine_desc->boot_params参数保存的是u-boot传入的启动参数的地址,如果没有传入启动参数,使用如下的默认参数: /* * This holds our default ...

  10. Python 基础(一)

    本章内容 1.编译和解释型语言的区别 2.Python的解释器 3.pyc文件 4.运行环境 5.变量 6.数据类型 7.字符编码 8.三元运算 编译和解释型语言的区别 编译器是把源程序的每一条语句都 ...