Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. const w_const = 1;
  2. const d_const = 20;
  3. const m_const = 3;
  4. const y_const = 2018;
  5. var month_mas: array [1..6,0..6] of integer;
  6. month_s: array [0..6] of string;
  7. function vis(y:integer):boolean;
  8. begin
  9. if ((y mod 4=0) and (y mod 100<>0)) or (y mod 400=0) then
  10. vis:=true
  11. else vis:=false;
  12. end;
  13.  
  14. function days(y:integer):integer;
  15. begin
  16. if vis(y) then days:=366
  17. else days:=365;
  18. end;
  19.  
  20.  
  21. function monthday(m,y:integer):integer;
  22. begin
  23. if m=2 then
  24. if vis(y) then monthday:=29
  25. else monthday:=28;
  26. case m of
  27. 1,3,5,7,8,10,12: monthday:=31;
  28. 4,6,9,11: monthday:=30;
  29. end;
  30. end;
  31.  
  32. function daysfromfirstjanuar(d,m,y:integer):integer;
  33. var i,sum:integer;
  34. begin
  35. sum:=0;
  36. for i:=1 to m-1 do begin
  37. sum:=monthday(i,y)+sum;
  38. end;
  39. sum:=sum+d;
  40. daysfromfirstjanuar:=sum;
  41. end;
  42.  
  43. function daysfromfirstyear(d,m,y:integer):integer;
  44. var i,sum:integer;
  45. begin
  46. sum:=0;
  47. for i:=1 to y-1 do begin
  48. sum:=days(i)+sum;
  49. end;
  50. sum:=sum+daysfromfirstjanuar(d,m,y);
  51. daysfromfirstyear:=sum;
  52. end;
  53.  
  54. function daysbetween(d1,m1,y1,d2,m2,y2:integer):integer;
  55. begin
  56. daysbetween:=daysfromfirstyear(d2,m2,y2)-daysfromfirstyear(d1,m1,y1);
  57. end;
  58.  
  59. function weekday2(d1,m1,y1,w1,d2,m2,y2:integer):integer;
  60. begin
  61. weekday2:=((w1+daysbetween(d1,m1,y1,d2,m2,y2)) mod 7 + 7) mod 7;
  62. end;
  63.  
  64. procedure monthmas(m,y:integer);
  65. var i,j,posi,posj:integer;
  66. begin
  67. for i:=1 to 6 do
  68. for j:=0 to 6 do
  69. month_mas[i,j] := 0;
  70. i:=1;
  71. j:=0;
  72. posi := 1;
  73. posj:=weekday2(d_const,m_const,y_const,w_const,1,m,y);
  74.  
  75. while(i <= monthday(m,y) ) do
  76. begin
  77. while (i <= monthday(m,y)) and (posj<=6) do
  78. begin
  79. month_mas[posi,posj] := i;
  80. inc(i);
  81. inc(posj);
  82. end;
  83. posj := 0;
  84. inc(posi);
  85. end;
  86.  
  87. end;
  88.  
  89. function week_cnt(m,y:integer):integer; //сколько в месяце недель (строк в month_mas, где есть хотя бы один не 0)
  90. begin
  91. if (month_mas[5,0] = 0) then week_cnt := 4
  92. else if (month_mas[6,0] = 0) then week_cnt := 5
  93. else week_cnt := 6;
  94. end;
  95.  
  96. procedure month(m,y:integer); //month__mas нужно переделать в строки
  97. var i,j:integer;
  98. begin
  99. for i:=0 to 6 do month_s[i]:='';
  100.  
  101. month_s[0]:='ПН ВТ СР ЧТ ПТ СБ ВС';
  102.  
  103. for i:=1 to week_cnt(m,y) do
  104. for j:=0 to 6 do
  105. begin
  106. if month_mas[i][j] = 0 then month_s[i] := month_s[i] + '--'
  107. else if month_mas[i][j] in [1..9] then month_s[i] := month_s[i] + '0' + inttostr(month_mas[i][j])
  108. else month_s[i] := month_s[i] + inttostr(month_mas[i][j]);
  109.  
  110. if j <> 6 then
  111. month_s[i] := month_s[i] + ' ';
  112.  
  113. end;
  114. end;
  115.  
  116. var a,b,i,j:integer;
  117.  
  118. begin
  119.  
  120. a := 6;
  121. b := 2018;
  122.  
  123. monthmas(a,b);
  124.  
  125. for i:=1 to 6 do begin
  126. for j:=0 to 6 do
  127. write(month_mas[i,j],' ');
  128. writeln;
  129. end;
  130.  
  131. month(a,b);
  132.  
  133. for i:=0 to week_cnt(a,b) do
  134. writeln(month_s[i]);
  135.  
  136. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement