【CF1023A】Single Wildcard Pattern Matching(模拟)
题意:给定两个串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(模拟)的更多相关文章
- 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 ...
- 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> ...
- Beginning Scala study note(5) Pattern Matching
The basic functional cornerstones of Scala: immutable data types, passing of functions as parameters ...
- 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 ...
- Symbols of String Pattern Matching
Symbols of String Pattern Matching in Introduction to Algorithms. As it's important to be clear when ...
- scala pattern matching
scala语言的一大重要特性之一就是模式匹配.在我看来,这个怎么看都很像java语言中的switch语句,但是,这个仅仅只是像(因为有case关键字),他们毕竟是不同的东西,switch在java中, ...
- Zhu-Takaoka Two-dimensional Pattern Matching
Two dimensional pattern matching. Details may be added later.... Corresponding more work can be foun ...
- [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 ...
- [学习笔记]编译sensetime发表的Single View Stereo Matching(SVS)遇到的问题
最近在研究用深度学习预测图像深度信息的方法,一开始用的是2017年CVPR上Godard大神的monodepth,代码在这里.这篇文章介绍了利用双目的consistency训练网络以对单张图像进行深度 ...
随机推荐
- cocos2d-x中的字符串操作
1:循环体中字符串的构造. 通常用于多个有规律的文件的名字,诸如:[NSString stringWithFormat:@"filed.png",i].我们可以通过spr ...
- 在Scrollview中使用AutoLayout
AutoLayout 与 UIScrollView的相遇是一个不可避免的场景,像UITableView.UIWebView这些都是继承于UIScrollView的,关于它们的autolayout布局大 ...
- 原型与原型继承demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CentOS7系统引导顺序以及排障
引导顺序 UEFi或BIOS初始化,运行POST开机自检 选择启动设备 引导装载程序, centos7是grub2 加载装载程序的配置文件:/etc/grub.d/ /etc/default/gru ...
- R,RJAVA 安装配置 详细版
准备工作 系统必须已经安装JDK 并配置好了环境变量. 注:安装的jdk r 以及系统 尽量保持位数一致 1.下载 R https://mirrors.tuna.tsinghua.edu.cn ...
- EditPlus 比较完整的快捷键记录
FileFtpUpload Ctrl+Shift+S 上传文件到FTP 服务器 FileNew Ctrl+N 新建普通的文本文档 FileNewHtml Ctrl+Shift+N 创建一个空白的 HT ...
- SQL登录注册练习
/class User package com.neusoft.bean; public class User { private int password; private String name; ...
- hdu4864不是一般的贪心
题目表达的非常清楚,也不绕弯刚开始以为最大权匹配,仔细一想不对,这题的数据双循环建图都会爆,只能先贪心试一下,但一想贪心也要双循环啊,怎么搞? 想了好久没头绪,后来经学长提醒,可以把没用到的先记录下来 ...
- Socketserver详解
Python3中的SocketServer socket并不能多并发,只能支持一个用户,socketserver 简化了编写网络服务程序的任务,socketserver是socket的在封装.sock ...
- 虚拟机上的Linux学习
title: 虚拟机上的Linux学习 date: 2018-08-08 15:48:28 updated: tags: [Linux,学习笔记] description: keywords: com ...