Cod sursa(job #635371)

Utilizator muscaTudose Vlad-Adrian musca Data 19 noiembrie 2011 10:54:39
Problema PalM Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 0.86 kb
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char a[501];
char b[501];
char c[501];
char d[501];
int n,m,i,j,max,nr;
void inversare()
{
	int w,x;
	w=strlen(c)-1;
	for(x=w;x>=0;x--)
		d[w-x]=c[x];
}
int palindrom()
{
	int w=strlen(c);
	if(!strcmp(c,d))
		return w;
	return 0;
}
int munte()
{
	int x;
	if(nr>1)
	for(x=1;x<=nr/2+nr%2-1;x++)
		if(c[x-1]>=c[x])
			return 0;
	return 1;
}
int main()
{
	freopen("palm.in","r",stdin);
	freopen("palm.out","w",stdout);
	gets(a);
	n=strlen(a)-1;
	for(i=n;i>=0;i--)
		b[n-i]=a[i];
	if(!strcmp(a,b))
		printf("%d",n+1);
	else
	{
		for(i=0;i<n-max;i++)
		{
			memset(c,0,sizeof(c));
			memset(d,0,sizeof(d));
			for(j=i;j<=n;j++)
			{
				c[j-i]=a[j];
				inversare();
				nr=palindrom();
				if(max<nr&&munte()==1)
					max=nr;
			}
		}
		printf("%d",max);
	}
	return 0;
}