Uses CRT; Type a_type=array[1..50,1..50] of integer; Var i,j,n:integer; a:a_type; t:boolean; {логическая переменная true (правда) или false (ложь)} x,y:integer; Label 1; {метка} Procedure Print(n:integer; a:a_type); {процедура вывода} Var i,j:integer; Begin for i:=1 to n do begin for j:=1 to n do write(a[i,j]:4); writeln(''); end; end; Procedure WinSh(x1,y1,x2,y2,col1,col2:word); {процедура вывода окна} Begin TextBackGround(black); Window (x1+1,y1+1,x2+1,y2+1); {тень - черный прямоугольник} ClrScr; TextBackGround(col1); Window(x1,y1,x2,y2); ClrScr; TextColor(col2); {рисование рамки} GotoXY(2, 1); write('г'); for i:=1 to x2-x1-2 do write('='); GotoXY(x2-x1,1); write('='); GotoXY(2,y2-y1+1); write('L'); for i:=1 to x2-x1-2 do write('='); GotoXY(x2-x1,y2-y1+1); write('-'); for j:=2 to y2-y1 do begin GotoXY(2,j); write('¦'); GotoXY(x2-x1,j); write('¦'); end; End; Procedure OddMagic(n:integer; var a:a_type); {Процедура формирования магического квадрата при нечетном n. Описание алгоритма в сопроводительной записке } Var i,j,k:integer; p,l:integer; Begin for i:=1 to n do for j:=1 to n do a[i,j]:=0; j:=n div 2 +1; p:=sqr(n); i:=1; a[i,j]:=1; for l:=2 to p do begin i:=i-1; j:=j+1; if (i=0) and (j<>n+1) then i:=n; if (j=n+1) and (i<>0) then j:=1; if ((i=0) and (j=n+1)) or (a[i,j]<>0) then {важен порядок условий!} begin i:=i+2; j:=j-1; end; a[i,j]:=l; end; end; Procedure Two (n:integer; var a:a_type); {Процедура построения квадрата при n обычной четности: n=6,10,14,18...} Var u,i,j,k,m,z:integer; b:a_type; Begin u:= n div 2; m:=(u-1) div 2; OddMagic(u,b); {вызов процедуры построения квадрата при нечет-ном u} k:=u*u; for i:=1 to n do for j:=1 to n do begin if (i>=1) and (i<=u) and (j>=1) and (j<=u) then a[i,j]:=b[i,j]; if (i>=u+1) and (i<=n) and (j>=u+1) and (j<=n) then a[i,j]:=b[i-u,j-u]+k; if (i>=1) and (i<=u) and (j>=u+1) and (j<=n) then a[i,j]:=b[i,j-u]+2*k; if (i>=u+1) and (i<=n) and (j>=1) and (j<=u) then a[i,j]:=b[i-u,j]+3*k; end; for i:=1 to u do if i=u div 2+1 then begin j:= u div 2+1; for k:=1 to m do begin z:=a[i,j]; {обмен данными} a[i,j]:=a[i+u,j]; a[i+u,j]:=z; j:=j-1 end; end
begin
var a:=ArrRandom(100,-10,10);
a.Println;
Writeln(a.Where(x->x>0).Count,' положительных, ',
a.Where(x->x<0).Count,' отрицательных')
end.
Тестовое решение:
4 -6 0 8 2 -2 -1 -8 -6 8 -3 7 4 -7 -5 9 0 -3 -7 1 0 -4 6 3 8 -10 4 9 3 5 8 5 5 8 10 4 -8 3 8 8 -9 2 7 -8 -7 -5 2 -9 0 9 -7 7 -2 -6 7 -2 -1 7 -10 2 4 1 -1 0 10 3 -8 6 -6 2 6 7 -1 -4 -1 8 0 3 0 2 -2 2 -1 5 1 -9 -4 1 -9 1 -6 -5 3 -4 -7 1 -7 -3 -7 1
51 положительных, 42 отрицательных