
10.01.2010, 03:47
|
Местный
|
|
Регистрация: 29.10.2009
Сообщения: 446
Репутация: 271
|
|
Интересная задачка)
Код:
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TDirection = (dRight, dDown, dLeft, dUp);
const
CCOLSROWS = 5;
var
A:Array [1..CCOLSROWS, 1..CCOLSROWS] of Integer;
Len, i, Index, x, y, c:Integer;
Direction:TDirection;
begin
//Подготовимся
Index:=1;
Len:=CCOLSROWS-1;
x:=1;
y:=1;
Direction:=dRight;
A[x,y]:=Index;
c:=0;
//заполняем массив
while (Len > 0) do
begin
for i:=1 to Len do
begin
Inc(Index);
case Direction of
dRight: Inc(x);
dDown: Inc(y);
dLeft: Dec(x);
dUp: Dec(y);
end;
A[x,y]:=Index;
end;
Inc(c);
if c = 3 then
begin
Dec(Len);
c:=1;
end;
if Direction = dUp then Direction:=dRight
else Direction:=Succ(Direction);
end;
//и выводим результат
for y:=1 to CCOLSROWS do
begin
for x:=1 to CCOLSROWS do
Write(StringOfChar(' ',5-Length(IntToStr(A[x,y])))+IntToStr(A[x,y]));
Writeln;
end;
Readln;
end.
|