function IsLeapYear(year: integer): boolean; begin if ((year mod 4 = 0) and (year mod 100 <> 0)) or (year mod 400 = 0) then IsLeapYear := true else IsLeapYear := false; end;
function IsValidDate(day, month, year: integer): boolean; begin IsValidDate := false;
if (year > 0) and (month >= 1) and (month <= 12) then begin case month of 1, 3, 5, 7, 8, 10, 12: if (day >= 1) and (day <= 31) then IsValidDate := true; 4, 6, 9, 11: if (day >= 1) and (day <= 30) then IsValidDate := true; 2: begin if IsLeapYear(year) then begin if (day >= 1) and (day <= 29) then IsValidDate := true; end else begin if (day >= 1) and (day <= 28) then IsValidDate := true; end; end; end; end; end;
procedure CalculateNextDay(var day, month, year: integer); begin if IsValidDate(day, month, year) then begin if (month = 12) and (day = 31) then begin writeln('Последний день месяца!'); writeln('С наступающим новым годом!'); day := 1; month := 1; year := year + 1; end else if (day = 31) and ((month = 1) or (month = 3) or (month = 5) or (month = 7) or (month = 8) or (month = 10)) then begin day := 1; month := month + 1; end else if (day = 30) and ((month = 4) or (month = 6) or (month = 9) or (month = 11)) then begin day := 1; month := month + 1; end else if (day = 29) and (month = 2) and IsLeapYear(year) then begin day := 1; month := month + 1; end else if (day = 28) and (month = 2) and not IsLeapYear(year) then begin day := 1; month := month + 1; end else begin day := day + 1; end; writeln('Завтра ', day, '.', month, '.', year); end else begin writeln('Некорректная дата!'); end; end;
program NextDay;
var
day, month, year: integer;
function IsLeapYear(year: integer): boolean;
begin
if ((year mod 4 = 0) and (year mod 100 <> 0)) or (year mod 400 = 0) then
IsLeapYear := true
else
IsLeapYear := false;
end;
function IsValidDate(day, month, year: integer): boolean;
begin
IsValidDate := false;
if (year > 0) and (month >= 1) and (month <= 12) then
begin
case month of
1, 3, 5, 7, 8, 10, 12: if (day >= 1) and (day <= 31) then IsValidDate := true;
4, 6, 9, 11: if (day >= 1) and (day <= 30) then IsValidDate := true;
2:
begin
if IsLeapYear(year) then
begin
if (day >= 1) and (day <= 29) then IsValidDate := true;
end
else
begin
if (day >= 1) and (day <= 28) then IsValidDate := true;
end;
end;
end;
end;
end;
procedure CalculateNextDay(var day, month, year: integer);
begin
if IsValidDate(day, month, year) then
begin
if (month = 12) and (day = 31) then
begin
writeln('Последний день месяца!');
writeln('С наступающим новым годом!');
day := 1;
month := 1;
year := year + 1;
end
else if (day = 31) and ((month = 1) or (month = 3) or (month = 5) or (month = 7) or (month = 8) or (month = 10)) then
begin
day := 1;
month := month + 1;
end
else if (day = 30) and ((month = 4) or (month = 6) or (month = 9) or (month = 11)) then
begin
day := 1;
month := month + 1;
end
else if (day = 29) and (month = 2) and IsLeapYear(year) then
begin
day := 1;
month := month + 1;
end
else if (day = 28) and (month = 2) and not IsLeapYear(year) then
begin
day := 1;
month := month + 1;
end
else
begin
day := day + 1;
end;
writeln('Завтра ', day, '.', month, '.', year);
end
else
begin
writeln('Некорректная дата!');
end;
end;
begin
writeln('Введите цифрами сегодняшнюю дату (число, месяц, год): ');
readln(day, month, year);
CalculateNextDay(day, month, year);
end.