uses crt;
const n=5;
type h=array[1..n,1..n] of integer;
var a,b: h; k1,k2: byte;
procedure input_output (c: h; var v: h);
var i,j: byte;
begin
for i:=1 to n do
begin
for j:=1 to n do
begin
c[i,j]:=random(19)-9;
write(c[i,j]:3);
end;
writeln;
end;
for i:=1 to n do
for j:=1 to n do
v[i,j]:=c[i,j];
end;
function kol (m: h): byte;
var l,k: byte;
begin
k:=0;
for l:=1 to n do
if m[l,l]>0 then inc(k);
kol:=k;
end;
procedure output_color (y: h);
var f,g: byte;
begin
for f:=1 to n do
begin
for g:=1 to n do
begin
if (f=g) and (y[f,g]>0) then
textcolor(5)
else textcolor(white);
write(y[f,g]:3);
end;
writeln;
end;
end;
begin
randomize;
clrscr;
writeln('исходные массивы: ',^j);
input_output(a,a);
writeln(^j);
input_output(b,b);
k1:=kol(a);
k2:=kol(b);
writeln;
writeln('результат: ');
if k1>k2 then output_color(a)
else if k1<k2 then output_color(b)
else writeln('массивы не соответствуют условиям задачи');
end.