2017.9.23 考试题一:回形遍历

(注:题目里有图片,不方便复制,这里只粘贴一个错误的代码)

(ps:这条代码有201错误,请读者回帖帮博主找错,谢谢)。

var
   f:array[-1..10000,-1..10000]of boolean;
   i,j,k,l:longint;  //l记录向上向下向左向右,i、j为指针。
   m,n,x,y,z:longint;
{//隐藏了读入读出
Procedure openn;
begin
  assign(input,'calc.in'); assign(output,'calc.out');
  reset(input); rewrite(output);
end;
Procedure closee;
begin
  close(input); close(output);
end;
}
BEGIN
  readln(n,m,x,y,z);
  fillchar(f,sizeof(f),false);
  for i:=0 to n do
  for j:=0 to m do
   f[i,j]:=true;//初始化数组
 i:=0; j:=0; l:=1;
  k:=-1;
 repeat
  if (l mod 4=1) then
     begin
    while f[i,j]=true do
      begin
      f[i,j]:=false;
      if((i=y)and(j=x))or(k<>-1)then inc(k);
      if k=z then break;
      inc(j);
     end;
    inc(l);
    dec(j);
    end;   //向右
       if (l mod 4=2)then
     begin
    while f[i,j]=true do
     begin
      f[i,j]:=false;
      if((i=y)and(j=x))or(k<>-1)then inc(k);
       if k=z then break;
      inc(i);
     end;
    inc(l);
    dec(i);
  end;   //向下
  if (l mod 4=3)then
   begin
    while f[i,j]=true do
     begin
      f[i,j]:=false;
      if((i=y)and(j=x))or(k<>-1)then inc(k);
      if k=z then break;
      dec(j);
     end;
     inc(l);
     inc(j);
   end;   //向左
  if (l mod 4=0)then
    begin
    while f[i,j]=true do
      begin
      f[i,j]:=false;
      if((i=y)and(j=x))or(k<>-1)then inc(k);
      if k=z then break;
      dec(i);
      end;
    l:=1;
    inc(i);
   end;   //向上
  until k=z;
  writeln(i,' ',j);
END.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值