044 - Wildcard Matching

2023-12-11 11:58
文章标签 matching 044 wildcard

本文主要是介绍044 - Wildcard Matching,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Implement wildcard pattern matching with support for '?' and '*'.

'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should be:
bool isMatch(const char *s, const char *p)Some examples:
isMatch("aa","a") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "*") → true
isMatch("aa", "a*") → true
isMatch("ab", "?*") → true
isMatch("aab", "c*a*b") → false
char *mystrstr(char *src, char *dst)
{int slen = strlen(src);int len = strlen(dst);char *a = src;char *b = dst;int cnt = 0, i;while (slen >= len) {b = dst;a = src + cnt;for (i = 0; i < len; i++) if (a[i] != b[i] && b[i] != '?') break;if (i == len) return src + cnt;slen--;cnt++;}return NULL;
}int dofun(char *s, char **pword, int pcnt, int begin, int end)
{if (pcnt < 1) return (begin || end || !*s)? 1:0;char *out = mystrstr(s, pword[0]);int pw0 = strlen(pword[0]);if (pcnt == 1) {if (!out) return 0;if (begin)return (end || mystrstr(s + strlen(s) - pw0, pword[0]))? 1:0;else return ((end && out == s) || (out == s && !out[pw0]))? 1:0;}char *ss = s;int cur = 0;if (!begin) {if (out != s) return 0;cur ++;ss += pw0;}if (!end) {int sslen = strlen(ss);int plen = strlen(pword[pcnt - 1]);if (sslen < plen) return 0;if (!mystrstr(ss + sslen - plen, pword[pcnt - 1]))return 0;char *t = s + strlen(s) - plen;*t = '\0';pcnt--;}for (; cur < pcnt; cur++) {out = mystrstr(ss, pword[cur]);int plen = strlen(pword[cur]);if (!out) return 0;ss = out + plen;}return 1;
}int isMatch(char* s, char* p) 
{int i, ret, begin, end, wcnt = 0;char *pword[2048] = {0};char *pw;/* split string by char '*' */begin = end = 0;if (*p == '*') begin = 1;if (p[strlen(p) - 1] == '*') end = 1;pw = strtok(p, "*");while (pw) {int pwlen = strlen(pw);pword[wcnt] = (char *)malloc(sizeof(char) * (pwlen + 1));memcpy(pword[wcnt++], pw, pwlen + 1);pw = strtok(NULL, "*");	}ret = dofun(s, pword, wcnt, begin, end);for (i = 0; i < wcnt; i++) free(pword[i]);return ret;
}


这篇关于044 - Wildcard Matching的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/480599

相关文章

leetcode#10. Regular Expression Matching

题目 Implement regular expression matching with support for ‘.’ and ‘*’. '.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input

ssh登录服务器报错“no matching host key type found. Their offer: ssh-rsa,ssh-dss”解决方法

这个错误表明你尝试使用 ssh 连接到远程服务器时,客户端和服务器之间没有匹配的 host key 类型。具体来说,远程服务器提供了 ssh-rsa 和 ssh-dss 类型的 host key,但你的 SSH 客户端配置可能不再支持这些较旧的算法。最近的 OpenSSH 版本默认禁用了不够安全的算法,如 ssh-rsa 和 ssh-dss。 解决方法 临时启用 ssh-rsa: 你可以在

One-Shot Imitation Learning with Invariance Matching for Robotic Manipulation

发表时间:5 Jun 2024 论文链接:https://readpaper.com/pdf-annotate/note?pdfId=2408639872513958656&noteId=2408640378699078912 作者单位:Rutgers University Motivation:学习一个通用的policy,可以执行一组不同的操作任务,是机器人技术中一个有前途的新方向。然而,

LeetCode - 10. Regular Expression Matching

10. Regular Expression Matching Problem's Link  ---------------------------------------------------------------------------- Mean:  给定一个串s和一个自动机p(模糊字符只含有'.'和'*'),问串s是否能够和自动机p匹配. analyse:

NLP-文本匹配-2017:BiMPM【Bilateral Multi-Perspective Matching for Natural Language Sentences】

NLP-文本匹配-2016:BiMPM【Bilateral Multi-Perspective Matching for Natural Language Sentences】

NLP-文本匹配-2016:Compare-Aggregate【A Compare-Aggregate Model for Matching Text Sequences】

NLP-文本匹配-2016:Compare-Aggregate【A Compare-Aggregate Model for Matching Text Sequences】

PeriodWave: Multi-Period Flow Matching for High-Fidelity Waveform Generation

preprintKorea Seoul, Korea 文章目录 abstractmethodFlow Matching for Waveform GenerationHigh-frequency Information Modeling for Flow Matching demo page, PeriodWave 三者最好,而且能把原声中的噪声去掉,GAN一类声码器做不到的。 Perio

PSMNet:Pyramid Stereo Matching Network学习测试笔记04-特征提取部分前向传播

写在前面的话: 2019年9月21日18:56:48好久没回来更新博客了。因为在实习中,实习的新问题一大堆,并且实习的工作内容整理了也是发在公司内网wiki,外面是不可能发的(专业,有节操)。周末再做做毕业论文相关的工作。 写在前面的话2: 2019年09月28日18:02:55补充说明:CSDN博客发布版权更新,如果您看了博客并且用到PSMNet相关东西,请注明引用原作者的文章: @inpr

PSMNet:Pyramid Stereo Matching Network学习测试笔记03-如何训练网络

写在前面的话: 2019年09月28日18:02:55补充说明:CSDN博客发布版权更新,如果您看了博客并且用到PSMNet相关东西,请注明引用原作者的文章: @inproceedings{chang2018pyramid, title={Pyramid Stereo Matching Network}, author={Chang, Jia-Ren and Chen, Yong-Sheng}

MKS MWH-5匹配器Automatc matching impedance Network手侧

MKS MWH-5匹配器Automatc matching impedance Network手侧