Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const w_const = 1;
- const d_const = 20;
- const m_const = 3;
- const y_const = 2018;
- var month_mas: array [1..6,0..6] of integer;
- month_s: array [0..6] of string;
- function vis(y:integer):boolean;
- begin
- if ((y mod 4=0) and (y mod 100<>0)) or (y mod 400=0) then
- vis:=true
- else vis:=false;
- end;
- function days(y:integer):integer;
- begin
- if vis(y) then days:=366
- else days:=365;
- end;
- function monthday(m,y:integer):integer;
- begin
- if m=2 then
- if vis(y) then monthday:=29
- else monthday:=28;
- case m of
- 1,3,5,7,8,10,12: monthday:=31;
- 4,6,9,11: monthday:=30;
- end;
- end;
- function daysfromfirstjanuar(d,m,y:integer):integer;
- var i,sum:integer;
- begin
- sum:=0;
- for i:=1 to m-1 do begin
- sum:=monthday(i,y)+sum;
- end;
- sum:=sum+d;
- daysfromfirstjanuar:=sum;
- end;
- function daysfromfirstyear(d,m,y:integer):integer;
- var i,sum:integer;
- begin
- sum:=0;
- for i:=1 to y-1 do begin
- sum:=days(i)+sum;
- end;
- sum:=sum+daysfromfirstjanuar(d,m,y);
- daysfromfirstyear:=sum;
- end;
- function daysbetween(d1,m1,y1,d2,m2,y2:integer):integer;
- begin
- daysbetween:=daysfromfirstyear(d2,m2,y2)-daysfromfirstyear(d1,m1,y1);
- end;
- function weekday2(d1,m1,y1,w1,d2,m2,y2:integer):integer;
- begin
- weekday2:=((w1+daysbetween(d1,m1,y1,d2,m2,y2)) mod 7 + 7) mod 7;
- end;
- procedure monthmas(m,y:integer);
- var i,j,posi,posj:integer;
- begin
- for i:=1 to 6 do
- for j:=0 to 6 do
- month_mas[i,j] := 0;
- i:=1;
- j:=0;
- posi := 1;
- posj:=weekday2(d_const,m_const,y_const,w_const,1,m,y);
- while(i <= monthday(m,y) ) do
- begin
- while (i <= monthday(m,y)) and (posj<=6) do
- begin
- month_mas[posi,posj] := i;
- inc(i);
- inc(posj);
- end;
- posj := 0;
- inc(posi);
- end;
- end;
- function week_cnt(m,y:integer):integer; //сколько в месяце недель (строк в month_mas, где есть хотя бы один не 0)
- begin
- if (month_mas[5,0] = 0) then week_cnt := 4
- else if (month_mas[6,0] = 0) then week_cnt := 5
- else week_cnt := 6;
- end;
- procedure month(m,y:integer); //month__mas нужно переделать в строки
- var i,j:integer;
- begin
- for i:=0 to 6 do month_s[i]:='';
- month_s[0]:='ПН ВТ СР ЧТ ПТ СБ ВС';
- for i:=1 to week_cnt(m,y) do
- for j:=0 to 6 do
- begin
- if month_mas[i][j] = 0 then month_s[i] := month_s[i] + '--'
- else if month_mas[i][j] in [1..9] then month_s[i] := month_s[i] + '0' + inttostr(month_mas[i][j])
- else month_s[i] := month_s[i] + inttostr(month_mas[i][j]);
- if j <> 6 then
- month_s[i] := month_s[i] + ' ';
- end;
- end;
- var a,b,i,j:integer;
- begin
- a := 6;
- b := 2018;
- monthmas(a,b);
- for i:=1 to 6 do begin
- for j:=0 to 6 do
- write(month_mas[i,j],' ');
- writeln;
- end;
- month(a,b);
- for i:=0 to week_cnt(a,b) do
- writeln(month_s[i]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement