데이터 구조: 문자열 의 패턴 일치 알고리즘 (미 완성)
2986 단어 데이터 구조
/* BF */
#include <iostream>
#include <cstring>
using namespace std;
#define MAXLEN 255
typedef struct
{
char ch[MAXLEN];
int length;
} SString;
int BF(const SString& s,const SString& p)
{
int i,j;
i=0; // i
while(i<s.length)
{
j=0; // j
while(j<p.length && s.ch[i]==p.ch[j]) // i,j 1,
{
i++;
j++;
}
if(j==p.length) // j==
return i-j+1; // p s
i = i-j+1; // i
}
return 0; // , 0
}
int main()
{
SString s; // s
SString p; // p
cin>>s.ch>>p.ch; // s p
s.length = strlen(s.ch); //
p.length = strlen(p.ch); //
int result;
result = BF(s,p);
if(result)
cout<<result<<endl; // , p s
else
cout<<"no found."<<endl; // , s p
return 0;
}