Pagini recente » Cod sursa (job #1048364) | Cod sursa (job #102303) | Cod sursa (job #264752) | Cod sursa (job #2587077) | Cod sursa (job #636887)
Cod sursa(job #636887)
#include<fstream>
#include<iostream>
using namespace std;
ifstream f("palm.in");
ofstream h("palm.out");
int n=0, v[510], best[510], poz, maxim, k, l[510], nr, bun, m, ok, mijloc, d, i;
char c, a[510];
int cautare_binara (int x, int s, int d)
{
if (s<x)
return -1;
else
for (i=s; i<=d; i++)
if (v[i]==v[x])
return i;
}
int main()
{
int i, j, poz;
nr = 1;
while (!f.eof())
{
f>>c;
n=n+1;
a[n]=c;
}
n=n-1;
for (i=1; i<=n; i++)
v[i]=int(a[i]);
best[1] = 1;
for (i = 2; i <= n; i++)
{
poz = cautare_binara(i, i+1, n);
bun=poz;
ok=1;
mijloc=(poz+i)/2;
j=i;
while (ok==1 && i<mijloc)
{
i=i+1;
bun=bun-1;
if (v[i]!=v[bun])
ok=0;
}
if (ok==0)
best[i]=1;
else
best[i]=(poz-j)+1;
}
maxim = 0;
for (i = 1; i <= n; i++)
if (maxim < best[i])
maxim = best[i];
h<<maxim<<'\n';
f.close();
h.close();
return 0;
}