daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program z_196;
  2.  
  3. {$APPTYPE CONSOLE}
  4. {$o-}
  5. uses
  6.   SysUtils;
  7. var
  8. a:array[0..101,0..101]of longint;
  9. i,j,n,m,i0,j0,ii,jj,d:longint;
  10. begin
  11.  reset(input,'input.txt');
  12.  rewrite(output,'output.txt');
  13.  read(n);
  14.  for i:=0 to n+1 do
  15.  for j:=0 to n+1 do
  16.   a[i,j]:=-1;
  17.  d:=1;
  18.  i0:=1;
  19.  j0:=1;
  20.  for i:=1 to n do
  21.  for j:=1 to n do
  22.   a[i,j]:=0;
  23.  for i:=1 to n*n do
  24.   begin
  25.    a[i0,j0]:=i;
  26.    if d=1 then inc(j0);
  27.    if d=2 then inc(i0);
  28.    if d=3 then dec(j0);
  29.    if d=4 then dec(i0);
  30.    if a[i0,j0]<>0 then
  31.       begin
  32.         if d=1 then dec(j0);
  33.         if d=2 then dec(i0);
  34.         if d=3 then inc(j0);
  35.         if d=4 then inc(i0);
  36.         if d=4 then d:=1 else inc(d);
  37.         if d=1 then inc(j0);
  38.         if d=2 then inc(i0);
  39.         if d=3 then dec(j0);
  40.         if d=4 then dec(i0);
  41.       end;
  42.   end;
  43.   for i:=1 to n do
  44.   begin
  45.   for j:=1 to n do
  46.    write(a[i,j],'  ');
  47.     writeln;
  48.   end;
  49. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top