Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program project1;
- uses
- DateUtils;
- const
- maxday: array [boolean, 1..12] of integer = (
- (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
- (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
- );
- var
- d1, d2, m1, m2, y1, y2, Count, n1, n2: integer;
- correct: boolean;
- function IsLeap(y: integer): boolean;
- begin
- Result := (y mod 400 = 0) or ((y mod 4 = 0) and not (y mod 100 = 0));
- end;
- function CheckCorrect(d, m, y: integer): boolean;
- begin
- Result := False;
- if (y < 0) and ((m < 0) or (m > 12)) and (d < 0) and (d > 31) then
- exit;
- if d > maxday[IsLeap(y)][m] then
- exit;
- Result := True;
- end;
- function Calculate(y1, y2, d1, d2: integer): integer;
- var
- Count, i, numberOfLeap, t1, t2: integer;
- begin
- Count := 0;
- t2 := (y2 div 4) - (y2 div 100) + (y2 div 400);
- t1 := (y1 div 4) - (y1 div 100) + (y1 div 400);
- numberOfLeap := t2 - (t1 + 1);
- Count := numberOfLeap * 366;
- Count := Count + 365 * ((y2 - y1) - numberOfLeap);
- Count := Count - d1 + d2;
- Result := Count;
- end;
- function DayOfYear(y, m, d: integer): integer;
- const
- indday: array [boolean, 1..12] of integer = (
- (1, 32, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
- (1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335)
- );
- var
- Count: integer;
- begin
- Count := indday[IsLeap(y)][m];
- Result := Count + d;
- end;
- begin
- Read(d1, m1, y1, d2, m2, y2);
- correct := CheckCorrect(d1, m1, y1);
- Count := 0;
- if (correct) then
- begin
- correct := CheckCorrect(d2, m2, y2);
- if (correct) then
- begin
- n1 := DayOfYear(y1, m1, d1);
- n2 := DayOfYear(y2, m2, d2);
- if (y1 > y2) then
- begin
- Count := Calculate(y2, y1, n2, n1);
- end
- else if (y1 = y2) then
- begin
- if (n1 > n2) then
- begin
- Count := Calculate(y2, y1, n2, n1);
- end
- else
- begin
- Count := Calculate(y1, y2, n1, n2);
- end;
- end
- else
- begin
- Count := Calculate(y1, y2, n1, n2);
- end;
- writeln(Count);
- readln();
- readln;
- end
- else
- begin
- Write('incorrect');
- readln;
- readln();
- end;
- end
- else
- begin
- Write('incorrect');
- readln;
- readln();
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement