{Задача "квадратна спіраль в одномірному масиві".}
PROGRAM ANXN;
CONST N=4;
VAR A: ARRAY[1..N,1..N] OF INTEGER;
B: ARRAY[1..N*N+3] OF INTEGER;
m,K,P,I, L, J: INTEGER;
BEGIN
for i:=1 to n do
for j:=1 to n do
begin
a[i,j]:= (i-1)*n +j;
b[(i-1)*n +j]:=a[i,j];
writeln('a[',i , '; ',j,']:= ',a[i,j], '= b[',(i-1)*n +j,']=', b[(i-1)*n +j]);
end;
writeln(' ');
writeln(' ');
K:=1;
M:=(N+1) div 2;
FOR P:=1 TO m do BEGIN
FOR J:=P TO N-P+1 do BEGIN
B[K]:=A[P,J];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
FOR I:=P+1 TO N-P+1 do BEGIN
B[K]:=A[I,N-P+1];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
FOR J:=N-P downTO P do BEGIN
B[K]:=A[N-P+1,J];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
FOR I:=N-P downTO P+1 do BEGIN
B[K]:=A[I,P];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
end;
writeln(' ');
writeln(' ');
FOR i:=1 TO n do BEGIN
FOR j:=1 TO n*n do BEGIN
case n mod j of
0..n-1: write(' b[', j+ n*(i-1) , ']');
end;
end; writeln(' ');
end;
writeln(' ');
writeln(' ');writeln(' ');
END.
PROGRAM ANXN;
CONST N=4;
VAR A: ARRAY[1..N,1..N] OF INTEGER;
B: ARRAY[1..N*N+3] OF INTEGER;
m,K,P,I, L, J: INTEGER;
BEGIN
for i:=1 to n do
for j:=1 to n do
begin
a[i,j]:= (i-1)*n +j;
b[(i-1)*n +j]:=a[i,j];
writeln('a[',i , '; ',j,']:= ',a[i,j], '= b[',(i-1)*n +j,']=', b[(i-1)*n +j]);
end;
writeln(' ');
writeln(' ');
K:=1;
M:=(N+1) div 2;
FOR P:=1 TO m do BEGIN
FOR J:=P TO N-P+1 do BEGIN
B[K]:=A[P,J];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
FOR I:=P+1 TO N-P+1 do BEGIN
B[K]:=A[I,N-P+1];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
FOR J:=N-P downTO P do BEGIN
B[K]:=A[N-P+1,J];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
FOR I:=N-P downTO P+1 do BEGIN
B[K]:=A[I,P];
write(' b[', k, ']=', b[k]);
K:=K+1;
END;
end;
writeln(' ');
writeln(' ');
FOR i:=1 TO n do BEGIN
FOR j:=1 TO n*n do BEGIN
case n mod j of
0..n-1: write(' b[', j+ n*(i-1) , ']');
end;
end; writeln(' ');
end;
writeln(' ');
writeln(' ');writeln(' ');
END.
Немає коментарів:
Дописати коментар