Cod sursa(job #635381)

Utilizator rusu_raduRusu Radu rusu_radu Data 19 noiembrie 2011 10:59:03
Problema PalM Scor 20
Compilator cpp Status done
Runda .com 2011 Marime 0.77 kb
#include <cstdio>
#include <cassert>
#include <cstring>
#define Nmax 505
#define InFile "palm.in"
#define OutFile "palm.out"

using namespace std;

int lg;
char s[Nmax];

void read();
void solve();

int main()
{
	assert (freopen (InFile, "r", stdin));
	assert (freopen (OutFile, "w", stdout));
	read();
	solve();
	return 0;
}

void read()
{
	scanf ("%s", s);
	lg=strlen (s);
}

void solve()
{
	int i, st, dr, l, lmax=1;
	for (i=0; i<lg; i++)
	{
		//impar
		l=0;
		for (st=i-1, dr=i+1, l=1; st>=0 && dr<lg && s[st]==s[dr] && s[st]<=s[st+1]; l+=2, st--, dr++);
		if (l>lmax) lmax=l;
		
		//par
		for (st=i, dr=i+1, l=0; st>=0 && dr<lg && s[st]==s[dr] && s[st]<=s[st+1]; l+=2, st--, dr++);
		if (l>lmax) lmax=l;
	}
	printf ("%d\n", lmax);
}