Cod sursa(job #635747)

Utilizator ELHoriaHoria Cretescu ELHoria Data 19 noiembrie 2011 14:42:57
Problema PalM Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 0.68 kb
#include <fstream>
#include <string>

using namespace std;

ifstream fin("palm.in");
ofstream fout("palm.out");

static inline int max(int a,int b)
{
	return a > b ? a : b;
}

int main()
{
	string s;
	fin>>s;
	int lgmax = 0 , lg = s.size();
	for(int i=1;i<lg-1;++i)
	{
		int currlg = 1;
		if(s[i-1]==s[i+1])
		for(int l=i-1,r=i+1;l>=0 && r<lg;--l,++r)
			if(s[l]<=s[l+1] && s[r]<=s[r-1] && s[l]==s[r]) currlg+=2;
		lgmax = max(lgmax,currlg);
		currlg = 2;
		if(s[i]==s[i-1])
			for(int l=i-2,r=i+1;l>=0 && r<lg;--l,++r)
				if(s[l]<=s[l+1] && s[r]<=s[r-1] && s[l]==s[r]) currlg+=2;
				
		lgmax = max(lgmax,currlg);
		
	}
	fout<<lgmax<<'\n';
	return 0;
}