Advertisement
Arfizato

rotate it boi

Apr 7th, 2020
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.58 KB | None | 0 0
  1. program ninetyDEGREEEEEEEEEEEE;
  2. uses WinCrt;
  3. type
  4.     mat= Array  [1..100,1..100] of Integer;
  5. var
  6.     m : mat ;
  7.     n : byte;
  8.  Procedure aff(m : mat ; n : Byte);
  9.    var
  10.       a,b: Byte;
  11.      begin
  12.          for a:=1 to n do
  13.           begin
  14.                 for b:=1 to n do
  15.                  write(m[a,b]:5);
  16.                 writeln;
  17.             end;
  18.            
  19.      end;
  20.      Procedure rempt(var m : mat ; n: Byte );
  21.     var
  22.     e: LongInt;
  23.     a,b: Byte;
  24.     ch: String;
  25.     begin
  26.         ch:='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,' ;
  27.         for a:=1 to n do
  28.             for b:=1 to n do
  29.                 begin
  30.                     val(copy(ch,1,pos(',',ch)-1),m[a,b],e);
  31.                     delete(ch,1,pos(',',ch));                      
  32.                 end;
  33.     end;
  34.     Procedure rotate( var m : mat ; n : Byte);
  35.       var
  36.             x,y,z,xy,l,c,a: Byte;
  37.             vf: Boolean;
  38.         begin
  39.              x:=1;
  40.              y:=0;
  41.             vf:=False;
  42.             while (vf= false)do
  43.                 begin
  44.                     y:=y+1;
  45.                     if y=n-x+1 then
  46.                      begin
  47.                      //     writeln('""""',x,y:4);
  48.                       x:=x+1;
  49.                         y:=x;
  50.                      end;
  51.                  z:=m[x,y];
  52.                  for a:=1 to 4 do
  53.                   begin
  54.                      l:=y;
  55.                      c:=x;
  56.                       c:= n - (c-1);
  57.                     xy:=m[l,c];
  58.                     m[l,c]:=z;
  59.                     z:=xy;
  60.                         //writeln(m[x,y],' [',x,',',y,']----->[',l,',',c,']',m[l,c]:2);
  61.                         x:=l;
  62.                         y:=c;
  63.                     end;
  64.                     //write('a',x,y:2);
  65.                     if n mod 2 = 0 then
  66.                         vf:= x = n div 2
  67.                     Else
  68.                         vf:= x = n div 2 +1;
  69.                 end;
  70.         End;
  71.         Procedure saisi(var n:Byte);
  72.          begin
  73.             repeat
  74.              ClrScr;
  75.              Write('N= ');
  76.               readln(n);
  77.             until n in [2..7];
  78.          end;
  79. begin
  80. saisi(n);
  81. rempt(m,n);
  82. aff(m,n);
  83. rotate(m,n);
  84. writeln;
  85. aff(m,n);
  86. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement