Cod sursa(job #636887)

Utilizator andreea29Iorga Andreea andreea29 Data 20 noiembrie 2011 00:58:52
Problema PalM Scor 10
Compilator cpp Status done
Runda .com 2011 Marime 0.94 kb
#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;   
}