Написать программу в паскале, которая формирует матрицу nXn в следующем виде: У меня есть программа, которая формирует матрицу в виде:
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 1
3 3 3 3 3 3 3 3 2 1
4 4 4 4 4 4 4 3 2 1
5 5 5 5 5 5 4 3 2 1
6 6 6 6 6 5 4 3 2 1
7 7 7 7 6 5 4 3 2 1
8 8 8 7 6 5 4 3 2 1
9 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
И программа для нее:
var
n,i,j: integer;
a: array[1..20,1..20] of integer;
begin
write('Введите размерность матрицы');
readln(n);
for i:=1 to n do
begin
for j:=1 to n do
begin
if i+j a[i,j]:=n-j+1;
write(a[i,j]:4);
end;
writeln;
end;
end.
i, j, k : integer;
a : array [0..9,0..9] of char;
procedure U(i,j:integer);
var c : char;
begin
c:=a[i,j]; a[i,j]:=' ';
if (c='W')and(a[i+1,j]='B') then U(i+1,j);
if (c='B')and(a[i+1,j]='W') then U(i+1,j);
if (c='W')and(a[i-1,j]='B') then U(i-1,j);
if (c='B')and(a[i-1,j]='W') then U(i-1,j);
if (c='W')and(a[i,j+1]='B') then U(i,j+1);
if (c='B')and(a[i,j+1]='W') then U(i,j+1);
if (c='W')and(a[i,j-1]='B') then U(i,j-1);
if (c='B')and(a[i,j-1]='W') then U(i,j-1);
end;
begin
assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);
for i:=1 to 8 do begin for j:=1 to 8 do
read(a[i,j]);
readln
end;
for i:=1 to 8 do
begin
a[0,i]:=' '; a[9,i]:=' '; a[i,0]:=' '; a[i,9]:=' '
end;
k:=0;
for i:=1 to 8 do
for j:=1 to 8 do
if a[i,j]<>' ' then
begin
k:=k+1; U(i,j)
end;
write(k);
close(output)
end.