GUYS MY PROGRAM SEEMS TO SHOW CORRECT OUTPUT IN MY SYSTEM;
BUT SHOWS wrong answer in spoj;
can anyone provide me with atleast one example where my program fails!
AT LEAST ONE!
include
include
using namespace std;
char str[11100001];
void preprocess(char *str,int l,int *table){
int i=0,j=1;
table[0]=0;
while(j<l){
while(str[i]==str[j]&&(j<l)){
table[j]=i+1;
i++;
j++;
}
if(i!=0)
i=table[i-1];
while(str[i]!=str[j]&&(j<l)) {
table[j]=0;
j++;
}
table[j]=i+1;
i++;j++;
}
}
int main(){
int n,l,i,j;
bool flag;
char ch;
while(scanf("%d",&n)!=EOF){
flag=false;
char pattern[n];
int table[n];
cin>>pattern;
preprocess(pattern,n,table);
cin>>str;
i=j=0;
l=strlen(str);
while(j<l){
if(pattern[i]==str[j]){
i++;
if(i==n){
flag=true;
cout<<j-n+1<<"\n";
if(i>0)
i=table[n-1];
}
}
else{
if(i>0)
i=table[i-1];
}
j++;
}
if(!flag)
cout<<"\n";
}
}