Cod sursa(job #635913)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 19 noiembrie 2011 15:34:50
Problema PalM Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 0.63 kb
#include <fstream>
using namespace std;

ifstream fi ("palm.in");
ofstream fo ("palm.out");

const int dim = 505;
char S[dim];
int M;

void cit ()
{
	fi.get (S, dim);
	
	int i;
	for (i = 0; S[i] >= 'a' && S[i] <= 'z'; i++);
	S[i] = 0;
}

void cal ()
{
	int i, s, d;
	for (i = 0; S[i] != 0; i++)
	{
		s = d = i;
		while (s-1 >= 0 && S[s-1] == S[s]) s--;
		while (S[d] == S[d+1]) d++;
		
		while (s >= 0 && S[d+1] != 0 && S[s-1] == S[d+1] && S[s-1] <= S[s] && S[d] >= S[d+1])
			s--, d++;
		
		M = max (M, d-s+1);
	}	
}

void afi ()
{
	fo << M;
}

int main ()
{
	cit ();
	cal ();
	afi ();
	return 0;
}