题解 | #字符串通配符#

字符串通配符

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-19 14:58
门头沟学院 Java
点赞 评论 收藏
分享
野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-20 18:18
是不是意味着秋招就完蛋了
花不开柳成荫:如果你是Java,是的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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