题解 | #字符串匹配#

字符串匹配

https://www.nowcoder.com/practice/fbdc522ef958455687654b38a4ca01e0

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1010;
string p, s[N];

string tolow(string s){
    string res;
    for(int i = 0; i < s.size(); i ++)
        res += tolower(s[i]);
    return res;
}

bool match(string a, string p){
    for(int i = 0, j = 0; i < a.size() || j < p.size(); i ++){
        if(i == a.size() || j == p.size()) return false;
        if(p[j] != '['){
            if(p[j] != a[i]) return false;
            j ++;
        }else{
            string s;
            j ++;
            while(p[j] != ']') s += p[j ++];
            j ++;
            if(s.find(a[i]) == -1) return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin>>n;
    for(int i = 0; i < n; i ++) cin>>s[i];
    cin>>p;
    for(int i = 0; i < n; i ++){
        if(match(tolow(s[i]), tolow(p))) cout<<i + 1<<" "<<s[i]<<endl;
    }
    return 0;
}

全部评论

相关推荐

机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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