Cod sursa(job #636940)

Utilizator bog29Antohi Bogdan bog29 Data 20 noiembrie 2011 03:02:07
Problema PalM Scor 20
Compilator cpp Status done
Runda .com 2011 Marime 0.53 kb
#include<fstream>
#include<string.h>
#define dmax 503
using namespace std;
ifstream in("palm.in");
ofstream out("palm.out");

char x[dmax];
int n;

int main()
{	
	in.getline(x, dmax, '\n');
	in.close();
	
	n = strlen(x);
	
	int i,j;
	int lng, mx=-1;
	
	for(i=1; i<n; i++)
	{	
		j=0;
		lng=0;
		while(x[i-j-1] == x[i+j+1] && x[i-j-1] <= x[i-j] && i-j-1>=0 && i+j+1 <=n-1)
		{	lng++;
			j++;
		}	
		
		if(lng > mx)
			mx = lng;
	}	
	if(mx)
		out<<2*mx+1;
	else out<<"1";
	
	out.close();
	return 0;
	
}