offer-Regular expression matching of sword finger

Source: Internet
Author: User

Huadian North Wind Blows
Key laboratory of cognitive computing and application, Tianjin University
Date: 2015/10/14

Topic Description:
Please implement a function to match the include '. ' and ' regular expressions. The characters in the pattern '. ' Represents any one character, and ' means that the preceding character can appear any time (including 0 times). In this point, a match is a string that matches all the characters of the entire pattern. For example, the string "AAA" matches the schema "A.A" and "ab*ac*a", but does not match "aa.a" and "Ab*a"

Analytical:
The problem with Microsoft is to find out how many sequential Fibonacci numbers in an array are similar problems. There are special circumstances that need to be considered ". *a", and there are other details to consider.

Code:

Class Solution {Public:bool match (char* str, char* pattern) {if (str[0]== ' ") {if (
            pattern[0]== ' ") return true;
            if (pattern[1]== ' * ') return match (str,pattern+2);
        return false;
        if (pattern[0]== ') return false;
                else {if (pattern[1]== ' * ') {bool result=false; result=result| |
                Match (STR,PATTERN+2);
                if (result) return true; while (str[0]==pattern[0]| | ((pattern[0]== '. ') && (str[0]!= ')) {result=result| |
                    Match (++STR,PATTERN+2);
                if (result) return true;
            return result; if (pattern[0]== '. ') | |
            (Str[0]==pattern[0])
            {return match (++str,++pattern); } returnFalse }
    }
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.