Cod sursa(job #638812)

Utilizator DEYDEY2Tudorica Andrei DEYDEY2 Data 21 noiembrie 2011 17:32:45
Problema PalM Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <string.h>
using namespace std;
ifstream fi("palm.in");
ofstream fo("palm.out");
char L[501];
int rez,n,lung,p;
int f(int p1,int p2)
{
	if (L[p1]!=L[p2])
		return p2-p1-1;
	if (p1==0 || p2==n-1)
		return p2-p1+1;
	if (L[p1]>=L[p1-1] && L[p2]>=L[p2+1] && L[p1-1]==L[p2+1])
		return f(p1-1,p2+1);
	return p2-p1+1;
}

int main()
{
	fi>>L;
	fi.close();
	n=strlen(L);
	rez=0;
	// centru format dintr-un singur caracter
	for (p=0;p<=n-1;p++)
	{
		lung=f(p,p);
		if (lung>rez)
			rez=lung;
	}
	// centru format din doua caractere
	for (p=0;p<=n-2;p++)
		if (L[p]==L[p+1])
		{
			lung=f(p,p+1);
			if (lung>rez)
				rez=lung;
		}
	fo<<rez;
	fo.close();
	return 0;
}