Cod sursa(job #636178)

Utilizator SmarandaMaria Pandele Smaranda Data 19 noiembrie 2011 17:36:25
Problema PalM Scor 10
Compilator cpp Status done
Runda .com 2011 Marime 0.95 kb
#include<cstdio>
#include<cstring>
using namespace std;
char s[1001];
char s1[1001];
char s2[1001];
void read() {
	gets(s);
}

long munte (char x[]) {
	long ok=1,l,j,okk1,i,okk2;
	l=strlen(x);
	for (i=0;i<l && ok;i++) {
		okk1=1;
		for (j=1;j<=i && okk1;j++)
			if (x[j]<x[j-1])
				okk1=0;
		okk2=1;
		for (j=i+1;j<l && okk1 && okk2;j++)
			if (x[j]>x[j-1])
				okk2=0;
		if (okk1 && okk2)
			ok=0;
	}
	if (ok==0)
		return 1;
	return 0;
}

void rez () {
	long i,l,j,k,u1,u2,max=-1;
	l=strlen(s);
	for (j=2;j<=l;j++)
		for (i=0;i<l;i++) {
			u1=u2=-1;
			for (k=i;k<=i+j-1;k++)
				s1[++u1]=s[k];
			for (k=u1;k>=0;k--)
				s2[++u2]=s1[k];
			s1[++u1]=NULL;
			s2[++u2]=NULL;
			if (strcmp(s1,s2)==0)
				if (munte(s1)==1)
					if (j>max)
						max=j;
		}
	if (max==-1)
		max=1;
	printf("%ld\n",max);
}

int main()
{
	freopen("palm.in","r",stdin);
	freopen("palm.out","w",stdout);
	
	read();
	rez();
	return 0;
}