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)
s.data[i]=cstr[i];
s.length=i;
}
int Pattern_index (sqstring s1,sqstring s2)
{
int i,j,k;
for (i=0; i<s2.length; i++)
{
j=i;
k=0;
while (j<s2.length&&k<s1.length&& (s1.data[k]== '? ' | | S2.data[j]==s1.data[k])
{
j + +;
k++;
}
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: