Pagini recente » Cod sursa (job #2300882) | Cod sursa (job #2582429) | Cod sursa (job #946461) | Cod sursa (job #1051632) | Cod sursa (job #1316481)
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
int n,k;
char a[16384],salv[16384];
int main()
{
int l=0,s=0,h;
char b[8192],*p,*q;
ifstream fin("substr.in");
fin >> n >> k >> a;
strcpy(salv,a);
for (int i=2;i<=n/2;i++)
{
for (int j=0;j<=n-i;j++)
{
l=0; p=a;
strncpy(b,p+j,i);
while (strstr(p,b)) {
q=strstr(p,b);
strcpy(q,q+i);
p=q;
l++;
}
strcpy(a,salv);
if (s<l) { s=l; h=strlen(b); }
}
}
ofstream fout("substr.out");
fout << h;
}