Advertisement
regergr

Untitled

Oct 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. program project1;
  2.  
  3. uses
  4. DateUtils;
  5.  
  6. const
  7. maxday: array [boolean, 1..12] of integer = (
  8. (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
  9. (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
  10. );
  11.  
  12. var
  13. d1, d2, m1, m2, y1, y2, Count, n1, n2: integer;
  14. correct: boolean;
  15.  
  16. function IsLeap(y: integer): boolean;
  17. begin
  18. Result := (y mod 400 = 0) or ((y mod 4 = 0) and not (y mod 100 = 0));
  19. end;
  20.  
  21. function CheckCorrect(d, m, y: integer): boolean;
  22. begin
  23. Result := False;
  24. if (y < 0) and ((m < 0) or (m > 12)) and (d < 0) and (d > 31) then
  25. exit;
  26. if d > maxday[IsLeap(y)][m] then
  27. exit;
  28. Result := True;
  29. end;
  30.  
  31. function Calculate(y1, y2, d1, d2: integer): integer;
  32. var
  33. Count, i, numberOfLeap, t1, t2: integer;
  34. begin
  35. Count := 0;
  36. t2 := (y2 div 4) - (y2 div 100) + (y2 div 400);
  37. t1 := (y1 div 4) - (y1 div 100) + (y1 div 400);
  38. numberOfLeap := t2 - (t1 + 1);
  39. Count := numberOfLeap * 366;
  40. Count := Count + 365 * ((y2 - y1) - numberOfLeap);
  41. Count := Count - d1 + d2;
  42. Result := Count;
  43.  
  44. end;
  45.  
  46. function DayOfYear(y, m, d: integer): integer;
  47. const
  48. indday: array [boolean, 1..12] of integer = (
  49. (1, 32, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
  50. (1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335)
  51.  
  52. );
  53. var
  54. Count: integer;
  55. begin
  56. Count := indday[IsLeap(y)][m];
  57. Result := Count + d;
  58. end;
  59.  
  60.  
  61.  
  62. begin
  63.  
  64. Read(d1, m1, y1, d2, m2, y2);
  65. correct := CheckCorrect(d1, m1, y1);
  66. Count := 0;
  67. if (correct) then
  68. begin
  69. correct := CheckCorrect(d2, m2, y2);
  70. if (correct) then
  71. begin
  72. n1 := DayOfYear(y1, m1, d1);
  73. n2 := DayOfYear(y2, m2, d2);
  74.  
  75.  
  76. if (y1 > y2) then
  77. begin
  78. Count := Calculate(y2, y1, n2, n1);
  79. end
  80. else if (y1 = y2) then
  81. begin
  82. if (n1 > n2) then
  83. begin
  84. Count := Calculate(y2, y1, n2, n1);
  85. end
  86. else
  87. begin
  88. Count := Calculate(y1, y2, n1, n2);
  89. end;
  90. end
  91. else
  92. begin
  93. Count := Calculate(y1, y2, n1, n2);
  94. end;
  95. writeln(Count);
  96. readln();
  97. readln;
  98. end
  99. else
  100. begin
  101. Write('incorrect');
  102. readln;
  103. readln();
  104.  
  105. end;
  106.  
  107. end
  108. else
  109. begin
  110. Write('incorrect');
  111.  
  112. readln;
  113. readln();
  114. end;
  115.  
  116. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement