[ create a new paste ] login | about

Link: http://codepad.org/Ts3ugbQv    [ raw code | output | fork ]

C++, pasted on Oct 3:
#include <iostream>
using namespace std;
 
bool isMatch(const char *s, const char *p) {
 
    const char* star=0;
    while (*s){
        if ((*p=='?')||(*p==*s)){
            s++;
            p++;
            continue;
        }
        else if (*p=='*'){
            star=p;
            p++;
            continue;
        }
        else if (star){ 
            p = star+1; 
            if(!*++s){
                if(!*p) {
                    p++;
                }
            }
            continue;
        }
        return false;
    }
    while (*p=='*'){
        p++;
    }
    return !*p;
}
 
int main() {
	// your code goes here
	const char *s = "aa";
	const char *p = "a*";
	cout << isMatch(s, p);
}


Output:
1
false


Create a new paste based on this one


Comments: