题解 | #字符串通配符#

字符串通配符

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

#include<iostream>
using namespace std;
bool isMatch(const char*s,const char*p)
{
    if(*s=='\0'&&*p=='\0')
    {
        return true;
    }
    if(*s=='\0'||*p=='\0')
    {
        return false;
    }
    if(*p=='?')
    {
        if(!isdigit(*p)&&!isalpha(*s))
        {
            return false;
        }
        return isMatch(s+1, p+1);
    }
    else if(*p=='*')
    {
        while(*p!='\0'&&*p=='*')p++;
        p--;
        return isMatch(s,p+1)||isMatch(s+1,p+1)||isMatch(s+1,p);
    }
    else if(tolower(*p)==tolower(*s))
    {
        return isMatch(s+1,p+1);
    }
    return false;
}
int main()
{
    string p,s;
    while(cin>>p>>s)
    {
        bool res=isMatch(s.c_str(),p.c_str());
        if(res)
        {
            cout<<"true"<<endl;
        }
        else
        {
            cout<<"false"<<endl;
        }
    }
    return 0;
}
全部评论

相关推荐

刷牛客的我很豁达:你是不是对算法有什么误解,你没手握两篇顶刊顶会,还想搞算法岗,有顶刊顶会在算法岗算才入门
点赞 评论 收藏
分享
LXXXXd:有点杂,想搞自动化的话没必要把法律的经历写上去
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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