题解 | #字符串通配符#

字符串通配符

https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036

#include <cctype>
#include <iostream>
#include <regex>
using namespace std;

int main() {
    string wildcard;
    string totest;
    string reg;
    getline(cin,wildcard);
    getline(cin,totest);
    int flag = 0;
    for(auto x:wildcard){
        if(x=='?'){
            reg+="[0-9a-zA-Z.]";
            flag = 0;
            continue;
        }if(x=='*'){
            if(flag == 1){
                continue;
            }else{
                reg+="[0-9a-zA-Z.]*";
                flag = 1;
                continue;
            }

        }else{
            flag = 0;
            x = tolower(x);
            reg.push_back(x);
        }
}
regex r(reg);
if(regex_match(totest, r)){
    cout<<"true";
}else{
    cout<<"false";
}
}
// 64 位输出请用 printf("%lld")

正则表达式很慢

全部评论

相关推荐

06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
07-02 13:52
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务