主题:求救:一个距阵的问题
binsuateks
[专家分:90] 发布于 2005-10-01 09:06:00
编写一个程序打印:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
回复列表 (共7个回复)
沙发
小田甜 [专家分:3910] 发布于 2005-10-02 21:04:00
begin
writeln('1 2 3 4);
writeln('12 13 14 5);
writeln('11 16 15 6);
writeln('10 9 8 7);
end.
板凳
小田甜 [专家分:3910] 发布于 2005-10-02 21:08:00
上面是开一个小玩笑;
program e2;
const
w:array[1..4,1..2]of integer
=((1,0),(0,-1),(-1,0),(0,1));
var
a:array [0..20,0..20]of integer;
n,l,t,i,j,x,y,p:integer;
begin
repeat
readln(n);
until (n<20) and (n>1);
p:=2;
if n>3 then p:=p+1;
if n>9 then p:=p+1;
l:=1;
x:=1;y:=n;
t:=1;
for i:=1 to n do begin
a[0,i]:=-1;
a[i,0]:=-1;
a[i,n+1]:=-1;
a[n+1,i]:=-1;
end;
repeat
a[x,y]:=l;
l:=l+1;
if a[x+w[t,1],y+w[t,2]]<>0 then t:=t+1;
if t=5 then t:=1;
x:=x+w[t,1];
y:=y+w[t,2];
until l>n*n;
for i:=1 to n do begin
for j:=1 to n do
write(a[j,n-i+1]:p);
writeln;
writeln;
end;
readln;
end.
{n是矩阵的宽}
3 楼
wywy [专家分:340] 发布于 2005-10-10 13:17:00
program e2;
const
w:array[1..4,1..2]of integer
=((1,0),(0,-1),(-1,0),(0,1));
var
a:array [0..20,0..20]of integer;
n,l,t,i,j,x,y,p:integer;
begin
repeat
readln(n);
until (n<20) and (n>1);
p:=2;
if n>3 then p:=p+1;
if n>9 then p:=p+1;
l:=1;
x:=1;y:=n;
t:=1;
for i:=1 to n do begin
a[0,i]:=-1;
a[i,0]:=-1;
a[i,n+1]:=-1;
a[n+1,i]:=-1;
end;
repeat
a[x,y]:=l;
l:=l+1;
if a[x+w[t,1],y+w[t,2]]<>0 then t:=t+1;
if t=5 then t:=1;
x:=x+w[t,1];
y:=y+w[t,2];
until l>n*n;
for i:=1 to n do begin
for j:=1 to n do
write(a[j,n-i+1]:p);
writeln;
writeln;
end;
readln;
end
4 楼
wywy [专家分:340] 发布于 2005-10-10 13:18:00
你的程序错了!(不过是小问题,)但是在程序里是运行不了的!请检查一下。
5 楼
bixuan [专家分:100] 发布于 2006-04-11 19:22:00
program xiti;
const n=10;
var h:array[0..n+1,0..n+1] of integer;
x,y,u,v,i,j,k:integer;
begin
for i:=0 to n+1 do
for j:=0 to n+1 do
if (i>=1)and(i<=n)and(j>=1)and(j<=n)
then
h[i,j]:=0
else h[i,j]:=1;
x:=1; y:=1; i:=0;k:=1;
h[x,y]:=k;
u:=1; v:=2;
repeat
while (h[u,v]=0) do
begin k:=k+1; x:=u; y:=v; h[x,y]:=k;
case i of
0:v:=y+1;
1:u:=x+1;
2:v:=v-1;
3:u:=u-1;
end;
end;
case i of
0:u:=u+1;
1:u:=u-1;
2:u:=u-1;
3:u:=u+1;
end;
case i of
0:v:=v-1;
1:v:=v-1;
2:v:=v+1;
3:v:=v+1;
end;
i:=(i+1) mod 4;
until k=n*n;
for i:=1 to n do
begin
for j:=1 to n do
write(h[i,j]:3);
writeln;
end;
readln;
end.
6 楼
bricks [专家分:20] 发布于 2006-05-05 17:25:00
简单题目,纯粹找规律!!
我来回复