Collusion matching of data structure

Source: Internet
Author: User

Using sequential structure storage string, write an algorithm pattern_index () that implements the matching of the collusion match, in which the wildcard character is only ". ", it can match any character successfully, for example, Pattern_index (". Re "," There is ") returns a result of 2.

The code is as follows:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxsize=100;

typedef struct
    char data[maxsize];
    int length;
} sqstring;

Sqstring str1,str2;
void Strassign (sqstring &s,char cstr[])
    int i;
    for (i=0; cstr[i]!= '; ++i)[i]=cstr[i];

int Pattern_index (sqstring s1,sqstring s2)
    int i,j,k;
    for (i=0; i<s2.length; i++)
        while (j<s2.length&&k<s1.length&& ([k]== '? ' | |[j][k])
            j + +;

        if (k>=s1.length)
            return (i);
    return 0;


int main ()

    char c1[100],c2[100];
    Gets (C1);
    Gets (C2);
    Strassign (STR1,C1);
    Strassign (STR2,C2);
    Cout<<pattern_index (STR2,STR1) <<endl;

Operation Result:

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: 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.