Cod sursa(job #37872)

Utilizator ZuziFilip Sanziana Zuzi Data 25 martie 2007 12:56:41
Problema Elimin 2 Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 4, Clasa a 10-a Marime 0.84 kb
#include<stdio.h>
#include<string.h>
char s[2005],max[2005],aux[2005];
int n,ck;


int palindrom(char s[2005])
{
 char cs[20005];
  strcpy(cs,s);
  strrev(cs);
  if (strcmp(s,cs)==0)
    return 1;
  else
    return 0;
}


void rezolv(int ex,char s[2005],int k)
{ int i;
  if ((!ex || (ex==1 && k>=ck)) && k>0)
  {
    for (i=0;i<k;i++)
     {
      strcpy(aux,s);
      aux[i]=0;
      strcat(aux,s+i+1);
       if (palindrom(aux))
	if ((max[0]==0 || (strcmp(max,aux)<0)) && aux[0]!='0')
	 strcpy(max,aux),ck=k,ex=1;
       rezolv(ex,aux,k-1);
     }
  }
}


int main()
{
  freopen("elimin2.in","r",stdin);
  freopen("elimin2.out","w",stdout);
  scanf("%s",s);
   if (palindrom(s))
     printf("%s",s);
   else
   { n=strlen(s);
     rezolv(0,s,n);
     printf("%s",max);
   }

  fcloseall();
  return 0;
}