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