zoukankan      html  css  js  c++  java
  • 面试题19:正则表达式匹配

    考察字符串匹配:正则表达式。

    C++版

    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    bool matchCore(char str[], char pattern[]){
        if(*str == '' && *pattern == '')
            return true;
        if(*str != '' && *pattern == '')
            return false;
        if(*(pattern+1) == '*'){
            if(*pattern == *str || (*pattern == '.' && *str != ''))
                return matchCore(str+1, pattern+2) || matchCore(str+1, pattern) || matchCore(str, pattern+2);
            else
                return matchCore(str, pattern+2);
        }
        if(*pattern == *str || (*pattern == '.' && *str != ''))
            return matchCore(str+1, pattern+1);
        return false;
    }
    
    bool match(char str[], char pattern[]){
        if(str == nullptr || pattern == nullptr)
            return false;
        return matchCore(str, pattern);
    }
    
    int main()
    {
        char str[] = {'a','a','a',''};
        char pattern[] = {'a','.','a',''};
        if(match(str, pattern))
            cout<<"yes."<<endl;
        else
            cout<<"no."<<endl;
        return 0;
    }
    
    
  • 相关阅读:
    ssm框架配置文件
    接口调用post请求参数在body中
    mysql三种连接方式
    jwt认证登录
    JWT工具类
    token的创建及解析
    IIS目录
    C# 增加多个分部类
    计算机知识
    Kibana 的安装(Windows版本)
  • 原文地址:https://www.cnblogs.com/flyingrun/p/13364751.html
Copyright © 2011-2022 走看看