Analysis of Microsoft Face test: Implement a very advanced character matching algorithm

Source: Internet
Author: User

Topic:

Give a string of very long strings, asking for a string that matches the requirements, such as the destination string: 123
1******3***2, 12*****3, we need to find these.

In fact, it is similar to some harmonious system.

Analysis:

A natural match is one that matches each character in a match.
Set your to match string length bit n, the pattern length bit m.
The worst case for any character in the string to match is the M-time, which means that the character is not in the pattern string.
So the worst case scenario is m*n this match, and the time complexity is O (m*n)

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Can be simple to achieve the following:

#include <iostream>  
#include <string.h>  
using namespace std;  
      
void Search_str (char* src, char* DST)  
{for  
        (int i=0; i < strlen (SRC); i++)  
        {  
                int j = 0;  
                for (j = 0; J < strlen (DST); j + +)  
                        if (src[i] = = Dst[j]) break  
                                ;  
                if (J < strlen (DST))  
                        cout << src[i];  
                else
                        cout << "*";  
        }  
}  
      
int main ()  
{  
        char s[] = "12436781563";  
        Char d[] = "123";  
        Search_str (S, d);  
        return 0;  
}

The output results are as follows:

12*3***1**3

Author: csdn Blog hhh3h

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.