【字符串】字符串通配符
来源:互联网 发布:python 开发环境 免费 编辑:程序博客网 时间:2024/06/18 08:24
字符串通配符
问题描述:在计算机中,通配符一种特殊语法,广泛应用于文件搜索、数据库、正则表达式等领域。现要求各位实现字符串通配符的算法。
要求:
实现如下2个通配符:
*:匹配0个或以上的字符(字符由英文字母和数字0-9组成,不区分大小写。下同)
?:匹配1个字符
输入:
通配符表达式;
一组字符串。
输出:
返回匹配的结果,正确输出true,错误输出false
先输入一个带有通配符的字符串,再输入一个需要匹配的字符串
输出:返回匹配的结果,正确输出true,错误输出false
样例输入:te?t*.*txt12.xls样例输出:
false
#include<iostream>#include<string>#include<cctype>using namespace std;bool Match(string match_str, string str){int i=0;int j=0;bool is_match=true;for (i =0,j=0; i <match_str.length()&&j<str.length(); i++,j++){if (match_str[i]!='?'&&match_str[i]!='*'){if (match_str[i]!=str[i]){is_match=false;break;}}else if (match_str[i]=='?'){if(isalnum(str[i]))continue;elseis_match=false;break;}else if (match_str[i]=='*'){while (i < match_str.length()) { if (match_str[i] == '*' || match_str[i] == '?') i++; else break; } if (match_str[match_str.length()-1] == '*') { is_match = true; break; } while (j < str.length() && isalnum(str[j])) { if (match_str[i] != str[j]) j++; else break; } if (str.length() == j ||false == isalnum(str[j])) { is_match = false; break; } if(j+1 == str.length() && i+1 != match_str.length() ) { is_match = false; break; } }} return is_match; }int main(){string match_str;string str;cin>>match_str>>str;for (int i = 0; i < match_str.length(); i++){match_str[i]=tolower(match_str[i]);}for (int j = 0; j < str.length(); j++){str[j]=tolower(str[j]);}if (Match(match_str,str))cout<<"true"<<endl;elsecout<<"false"<<endl;return 0;}
0 0
- 字符串通配符
- 字符串通配符
- 字符串通配符
- 字符串通配符
- 字符串通配符
- 【字符串】字符串通配符
- 通配符匹配字符串
- 字符串通配符匹配问题
- 字符串通配符匹配*,?算法
- 华为oj_字符串通配符
- 华为oj 字符串通配符
- 华为oj 字符串通配符
- OJ---字符串通配符
- 华为OJ:字符串通配符
- 华为OJ:字符串通配符
- 字符串通配符(OJ)
- Huawei OJ-字符串通配符
- 通配符字符串匹配
- Button和ImageButton
- 理解矩阵(三)
- jsp中el表达式的应用
- 随笔~游戏工作室的招聘
- 重建二叉树
- 【字符串】字符串通配符
- 遍历日历的每一天
- jquery.extend() 与 jquery.fn.extend() 的区别
- 关于gluster数据不同步的处理
- Spring之Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectio
- Android版本和API Level的对应关系
- 【oracle11g,13】表空间管理2:undo表空间管理(调优) ,闪回原理
- 【C#获取音频文件的播放时间】
- 关于wampserver中mysql数据库乱码