{$mode objfpc}{$H-}{$R+}{$T+}{$Q+}{$V+}{$D+}{$X-}{$warnings on}
program fecha_valida_v01;

// Es aceptable, aunque la función 'dia_ok' posiblemente hace
// demasiadas cosas

function anyo_ok(anyo: integer): boolean;
const
	MinAnyo = 1900;
	MaxAnyo = 2123;
begin
	result := (anyo >= MinAnyo) and (anyo <= MaxAnyo);
end;

function mes_ok(mes: integer): boolean;
const
	Ene = 1;
	Dic = 12;
begin
	result := (mes >= Ene) and (mes <= Dic);
end;

function es_bisiesto(anyo: integer): boolean;
begin
	result := (Anyo mod 4 = 0) and (Anyo mod 100 <> 0) or
		(Anyo mod 400 = 0);
end;

function dia_ok(anyo, mes, dia: integer): boolean;
begin
	case mes of
	1, 3, 5, 7, 8, 10, 12:
		result := (dia >= 1) and (dia <=31);
	2:
		if es_bisiesto(anyo) then 
   			result := (dia >= 1) and (dia <= 29)
		else 
			result := (dia >= 1) and (dia <= 28);
	otherwise
		result := (dia >= 1) and (dia <= 30);
	end;
end;

function fecha_ok(anyo, mes, dia: integer): boolean;
begin
	result := anyo_ok(anyo) and mes_ok(mes) and dia_ok(anyo, mes, dia);
end;

const
	Anyo = 2018;
	Mes = 2;
	Dia = 29;

begin
	writeln(fecha_ok(Anyo, Mes, Dia));
end.


