"head.h"
view plaincopy to clipboardprint #include
#include
using namespace std;
class STRING
{
public:
void GetString();
void GetSubString();
void KMP();
void Print();
private:
void GetNext();
string str;
string sub;
int next[1000];
int strlen;
int sublen;
};
void STRING::GetString()
{
cout<<"Please Input The MainString :"<
strlen=str.length();
}
void STRING::GetSubString()
{
cout<<"Please Input The SubString :"<
sublen=sub.length();
}
void STRING::KMP()
{
cout<<"KMP Method Called !"<
int i,j;
i=j=0;
while(i
if(j==-1||str[i]==sub[j])
{
i++;
j++;
}
else
{
j=next[j];
}
}
if(j==sublen)
{
cout<<"Succeed ! Position = "<
else
{
cout<<"Failed !"<
}
void STRING::Print()
{
cout<<"Main String = "<
strlen=str.length();
}
void STRING::GetSubString()
{
cout<<"Please Input The SubString :"<
sublen=sub.length();
}
void STRING::KMP()
{
cout<<"KMP Method Called !"<
int i,j;
i=j=0;
while(i
if(j==-1||str[i]==sub[j])
{
i++;
j++;
}
else
{
j=next[j];
}
}
if(j==sublen)
{
cout<<"Succeed ! Position = "<
else
{
cout<<"Failed !"<
}
void STRING::Print()
{
cout<<"Main String = "<