const MAXN=55;
finp='NZTABLE.INP';
fout='NZTABLE.OUT';
var n, kc, p: longint;
a,b: array[1..MAXN, 1..MAXN] of longint;
procedure nhap;
var i,j:longint;
begin
readln(n);
for i:=1 to n do
for j:=1 to n do read(a[i,j]);
end;
procedure tinh(i,j:longint);
begin
if (a[i,j]>0) then b[i,j]:=a[i,j]
else
begin
b[i,j]:=-maxlongint;
kc:=maxlongint;
for p:=1 to n do
if (a[p,j]<>0) then
if ((abs(i-p)<kc) or ((abs(i-p)=kc) and (a[p,j]>b[i,j]))) then
begin
kc:=abs(i-p);
b[i,j]:=a[p,j];
end;
for p:=1 to n do
if (a[i,p]<>0) then
if ((abs(j-p)<kc) or ((abs(j-p)=kc) and (a[i,p]>b[i,j]))) then
begin
kc:=abs(j-p);
b[i,j]:=a[i,p];
end;
if (kc=maxlongint) then b[i,j]:=0;
end;
end;
procedure giai;
var i,j:longint;
begin
for i:=1 to n do
for j:=1 to n do tinh(i,j);
for i:=1 to n do
begin
for j:=1 to n do write(b[i,j],' ');
writeln;
end;
end;
begin
assign(input, finp);reset(input);
assign(output, fout);rewrite(output);
nhap;
giai;
close(input);
close(output);
end.
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Thứ Tư, 27 tháng 4, 2022
NZTABLE PASCAL
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.