Advertisement
_juggernaut_

xoanoc

Feb 17th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.02 KB | None | 0 0
  1. uses crt;
  2. var n,i,j,s,canle:longint;
  3.         a:array[1..1000,1..1000]of longint;
  4. function check:boolean;
  5. var i,j:longint;
  6. begin
  7.     check:=false;
  8.     for i:=1 to n do
  9.         for j:=1 to n do
  10.             if a[i,j]=0 then begin check:=true; break end
  11. end;
  12. function sochuso:longint;
  13. var d:longint;
  14. begin
  15.     d:=0;
  16.     while s<>0 do begin inc(d); s:=s div 10 end;
  17.     sochuso:=d;
  18. end;
  19. procedure phai;
  20. begin inc(s); inc(j); a[i,j]:=s; end;
  21. procedure trai;
  22. begin inc(s); dec(j); a[i,j]:=s; end;
  23. procedure tren;
  24. begin inc(s); dec(i); a[i,j]:=s; end;
  25. procedure duoi;
  26. begin inc(s); inc(i); a[i,j]:=s; end;
  27.  
  28. begin
  29.     write('N='); readln(n);
  30.     for i:=1 to n do
  31.         for j:=1 to n do
  32.             a[i,j]:=0;
  33.     i:=1; j:=1; a[1,1]:=1; s:=1;
  34.  
  35.     while check do
  36.         begin
  37.             while (j+1<=n) and (a[i,j+1]=0) do phai;
  38.             while (i+1<=n) and (a[i+1,j]=0) do duoi;
  39.             while (j-1>=1) and (a[i,j-1]=0) do trai;
  40.             while (i-1>=1) and (a[i-1,j]=0) do tren;
  41.         end;
  42.  
  43.     canle:=sochuso+1;
  44.     for i:=1 to n do
  45.         begin writeln;
  46.                     for j:=1 to n do write(a[i,j]:canle);
  47.         end;
  48.     readln
  49. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement