Cod sursa(job #636407)

Utilizator BarracudaFMI-Alex Dobrin Barracuda Data 19 noiembrie 2011 19:45:11
Problema PalM Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.54 kb
#include<stdio.h>
#include<string.h>
FILE*f=fopen("PalM.in","r");
FILE*g=fopen("PalM.out","w");
int v[30],y,r,i,j,t,n,p;
char s[501],x[501];
int main (){
	fscanf(f,"%s",s);
	for(i=0;i<strlen(s);i++)
		v[s[i]-96]++;
	n=26;
	y=n;
	t=0;
	while((t!=1)&&(y!=0)){
		p=y;
		while(v[p]<=1){
			p--;
		}
		j=p+1;
		while((j<n)&&(v[j]%2!=1)){
			j++;
		}
		if(v[j]==1)
			t=1;
		y=p-1;
	}
	for(i=1;i<j;i++){
		if(v[i]>1){
			if(v[i]%2==0)
				r+=v[i];
			else
				r+=v[i]-v[i]%2;
		}
	}
	r+=v[j];
	fprintf(g,"%d\n",r);
	return 0;
}