Cod sursa(job #240780)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 8 ianuarie 2009 18:06:16
Problema Tablete Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.95 kb
Program tablete;
VAR
 f,g:text;
 n,i,j,k,x:word;
 p:longint;
 m: array [1..1000,1..1000] of longint;
begin
 assign(f,'tablete.in');reset(f);
 assign(g,'tablete.out');rewrite(g);
 readln(f,n,k);
 for i:=1 to n do
   for j:=1 to n do
    begin
     inc(p);
     m[i,j]:=p;
    end;
 if(k mod 2 =0) then
  for i:=1 to n do
   begin
    for j:=1 to n do
     write(g,m[i,j],' ');
    writeln(g);
   end;
 p:=0;
 if(k mod 2=1)and(n mod 2=0) then
  begin
   for i:=1 to n do
     for j:=1 to k do
      begin
        inc(p); x:=0;
        if(i mod 2=1) and (j=k) then begin m[i,j]:=p+1; x:=1; end;
        if(i mod 2=0) and (j=1) then begin m[i,j]:=p-1; x:=1; end;
        if(x<>1) then m[i,j]:=p; end;
   p:=n*k;
   for i:=1 to n do
    for j:=k+1 to n do
     begin inc(p); m[i,j]:=p; end;
   for i:=1 to n do
    begin
     for j:=1 to n do
      write(g,m[i,j],' ');
     writeln(g);
    end;
  end;
 close(f);close(g);
end.