#include<bits/stdc++.h>
using namespace std;
void child(int*,string);
void parent(int*,string,string);
int main()
{
int i,j,k,length;
string needle,haystack,temp1,temp2;
while(cin>>length)
{
needle+='0';
haystack+='0';
cin>>temp1>>temp2;
needle+=temp1;
haystack+=temp2;
if(needle.length()>haystack.length()){
cout<<endl;
needle.clear();
haystack.clear();
continue;
}
int lps[needle.length()];
child(lps,needle);
parent(lps,needle,haystack);
needle.clear();
haystack.clear();
cout<<endl;
}
return 0;
}
void child(int lps[],string needle)
{
int i=2,j,len=0;
lps[1]=0;
while(i<needle.length())
{
if(needle[i]==needle[len+1])
{
len++;
lps[i++]=len;
}
else
{
if(len!=0)
{
len=lps[len];
}
else{
lps[i++]=0;
}
}
}
}
void parent(int lps[],string needle,string haystack)
{
int i=1,len=0;
while(i<=haystack.length()){
//cout<<i<<" "<<len+1<<endl;
if(len==needle.length()-1){
cout<<i-len-1<<endl;
len=lps[len];
}
if(i>=haystack.length())
break;
if(haystack[i]==needle[len+1]){
len++;
i++;
}
else{
if(len!=0){
len=lps[len];
}
if(len==0){
i++;
}
}
}
}
Can someone help me in finding out why it is not getting accepted, What changes should i make to correct this code?