Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Mx_4;
- type MyArray=array of array of Integer;
- var a,b:MyArray;
- i,j,m,n:Word;
- procedure PullArray(var a:MyArray; var m,n:Word);
- var Fin:Text;
- i,j:Word;
- begin
- Assign(Fin,'in.txt');
- ReSet(Fin);
- ReadLn(Fin,m,n); // array size
- SetLength(a,m+2,n+2);
- for i:=1 to m do
- begin
- for j:=1 to n do
- Read(Fin,a[i,j]);
- ReadLn(Fin);
- end;
- Close(Fin);
- end;
- procedure FlushArray(var b:MyArray; m,n:Word; bulk:Boolean);
- var i,j:Word;
- begin
- case bulk of
- False: begin
- SetLength(b,m+2,n+2);
- for i:=0 to m+1 do b[i,0]:=0;
- for i:=0 to m+1 do b[i,n+1]:=0;
- for j:=0 to n+1 do b[0,j]:=0;
- for j:=0 to n+1 do b[m+1,j]:=0;
- end;
- True: begin
- SetLength(b,0,0);
- SetLength(b,m+2,n+2);
- for i:=0 to m+1 do
- for j:=0 to n+1 do
- b[i,j]:=0;
- end;
- end;
- end;
- function Compute(a:MyArray; m,n:Word; y,x:Word; mode:Integer):Integer;
- var i,i1,i2,j,j1,j2:Word;
- s:Integer;
- begin
- if mode=1 then begin //down-right
- i1:=y+1;
- j1:=x+1; j2:=n;
- i2:=m;
- end else begin //upper-left
- i1:=1;
- j1:=1; j2:=x-1;
- i2:=y-1;
- end;
- s:=0;
- {if i1<1 then i1:=1;
- if i2>m then i2:=m;
- if j1<1 then j1:=1;
- if j2>n then j2:=n;}
- for i:=i1 to i2 do
- for j:=j1 to j2 do
- s:=s+a[i,j];
- Compute:=s;
- end;
- procedure PushArray(b:MyArray; m,n:Word);
- var i,j:Word;
- Fout:Text;
- begin
- Assign(Fout,'out.txt');
- ReWrite(Fout);
- WriteLn(Fout,m,' ',n);
- for i:=1 to m do
- begin
- for j:=1 to n do
- Write(Fout,b[i,j]:4,' ');
- WriteLn(Fout);
- end;
- Close(Fout);
- end;
- //main
- begin
- PullArray(a,m,n);
- FlushArray(a,m,n,False);
- SetLength(b,m+1,n+1);
- for j:=1 to ((n+1) div 2) do
- for i:=1 to m do
- b[i,j]:=Compute(a,m,n,i,j,1);
- for j:=((n+1) div 2 +1) to n do
- for i:=1 to m do
- b[i,j]:=Compute(a,m,n,i,j,2);
- PushArray(b,m,n);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement