题解 | #字符串通配符#

字符串通配符

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

#include <bits/stdc++.h>
using namespace std;


string c, d;
bool strmatch(int i, int j){
    if (i >= c.size() and j >= d.size()) return true;
    if (i >= c.size() or j >= d.size()) return false;
    if (c[i]=='?'){
        if (isalpha(d[j]) or isdigit(d[j])) return strmatch(i+1, j+1);
        return false;
    }
    else if (c[i]=='*'){
        if (isalpha(d[j]) or isdigit(d[j])) return strmatch(i+1, j) || strmatch(i, j+1) || strmatch(i+1, j+1);
        else return strmatch(i+1, j);
    }
    else {
        if (c[i] != d[j]) return false;
        return strmatch(i+1, j+1);
    }
}


int main(){
    string a, b;
    cin >> a >> b;
    bool hasstar = false;
    for(int i = 0; i < a.size(); i++){
        if (!hasstar or a[i] != '*') c.push_back(tolower(a[i]));
        if (a[i] == '*') hasstar=true;
        if (a[i] != '*') hasstar=false;
    }
    for(int i = 0; i < b.size(); i++) d.push_back(tolower(b[i]));
    // cout << c << " " << d << endl;
    if (strmatch(0, 0)) cout << "true";
    else cout << "false";
    return 0;
}

全部评论

相关推荐

08-11 11:16
已编辑
天津工业大学 Java
程序员牛肉:我个人觉得就是中厂吧,运气好点能进个大厂。 八月找暑期当然找不到了,现在各大厂的暑期实习一般都是三月多开放,五月多收尾。你这都八月多了肯定找不到,相当于是半夜去逛商场了。吃了信息差的亏了。 简历上的实习部分有很大的问题。你作为应聘后端的同学,实习经历中看不出来你干了哪些后端需求,一眼扫过去都是一些配置类的需求,Swagger文档就不要拿出来了。以及撰写技术文档和写单测这种经历。 所以建议你重写一下你的实习部分,重点突出需求,需求啊同学。比如详细的说一下自己是怎么使用GraalVM以及虚拟线程提高项目启动速度的。 调研了什么技术,有什么收获,有什么可以拿出来讲的技术点。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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