求最长重复子串的代码,不知道哪里出了问题

#include
#include
using namespace std;
void GetNext(char s[], int next[], int length);
int MaxRepSubString(char s[],int &l,int length);
int main ()
{
char v[1000];
char c;
int i=0;
while((c=getchar())!=EOF)
{
v[i]=c;
i++;
}
v[i]='\0';
int l;
int pos = MaxRepSubString(v,l,i);
if (pos == -1)
printf("-1\n");
else
{
int j;
for(j=pos;j<pos+l;j++)
printf("%c",v[j]);
printf(" ");
printf("%d\n",pos);

}
return 0;
}

void GetNext(char s[], int next[], int length) {
int i = 0;
int j = -1;
next[0] = -1;
while (i < length) {
if (j == -1 || s[i] == s[j]) {
i++;
j++;
next[i] = j;
}
else
j = next[j];
}
}

int MaxRepSubString(char s[],int &l,int length) {
int i,j,k,n;
l=0;
int pos=-1;
char t[1000];
int next[1000];
for(i=0;i {
for(j=i;j {
for(k=i,n=0;k t[n]=s[k];
t[n]='\0';
GetNext(t,next,n);
while(next[n-1]>((n%2)?((n-1)/2):(n/2)))
{
int m;
char w[1000];
for(m=0;m w[m]=t[m];
w[m]='\0';
GetNext(w,next,m);
next[n-1]=next[m-1];
}
if(next[n-1]>l)
{
l=next[n-1];
pos=i;
}
}
}
return pos;
}