Wildcard Matching
来源:互联网 发布:页面加载时执行js 编辑:程序博客网 时间:2024/06/16 18:41
题目描述:
‘?’ 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
此题与之前一体颇为相似(Regular Expression Matching),重点依然是星号,标记‘*’即可。
代码如下:
bool isMatch(string s, string p) { int i = 0, j = 0, tempi = -INT_MIN,tempj=-INT_MIN; for(;j<s.size();) { if ( p[i] == '?'||s[j] == p[i] ) { i++; j++;//正常情况 } else if (p[i] == '*') { tempj= j; tempi = i; i++;//先跳过*号,并记录他们 } else if (tempi >= 0) { tempj++; j= tempj; i= tempi+ 1; } else { return false; } } while (i<p.size()&& p[i] == '*') i++; if(i==p.size()) return 1; return 0; }
阅读全文
0 0
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- 104. Maximum Depth of Binary Tree
- Centos7+Hadoop+Spark+Zookeeper+Hbase之集群搭建
- 图
- 聚集索引和非聚集索引
- 什么struts2
- Wildcard Matching
- 构造函数可以为虚函数吗?
- Qt-JSON的使用
- 在 Kali Linux 中如何安装 Google Chrome
- angular1.5的自身缺陷之一
- UC/OS-II(一)资料绪论
- JavaWeb中的JSTL操作
- Qt 学习之路 2(22):事件总结
- 前面有人贡献,后辈才有强大的靠山