Wildcard Matching

来源:互联网 发布:美工使用的软件 编辑:程序博客网 时间:2024/06/03 23:52

迭代:

#include<iostream>using namespace std;class Solution{public: bool isMatch(const char *s, const char *p)        {            int i=0,j=0;            bool str=false;            for(;s[i]!='\0';i++,j++)            {                switch (p[j])                {                case '?':                       break;                case '*':                    while(p[j]=='*')                        j++;                    if(p[j]=='\0')                         return true;                    str=true;                    i--;                    j--;                    break;                default:                    if(s[i]!=p[j])                    {                           if(!str)                            return false;                        else                            j--;                            break;                    }                }            }            while(p[j++]=='*');            return p[j]=='\0';        }};void main(){    Solution solution;    cout<<solution.isMatch("aab","*a*b");}
0 0
原创粉丝点击