Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool match(string needle, string haystack) {
- if (needle.size() == 0 && haystack.size() == 0)
- return true;
- if (needle.size() == 0)
- return false;
- if (needle == "*")
- return true;
- if (needle[0] == '?')
- if (haystack.size() != 0)
- return match(needle.substring(1, needle.size()), haystack.substring(1, haystack.size()));
- else
- return false;
- if (needle[0] == '*') {
- auto char = needle[1];
- int index = 0;
- while(haystack[index] != char) {
- index++;
- if (index >= haystack.size())
- return false;
- }
- return match(needle.substring(1, needle.size()), haystack.substring(index, haystack.size()));
- }
- if (needle[0] == haystack[0])
- return match(needle.substring(1, needle.size()), haystack.substring(1, haystack.size()));
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement