Hello people!
I have read most of the useful threads about this problem, but still I am getting WA.
I have learned that there are more than one test case in the input.
And I fixed it and don't know where may be my other mistake(s).
Code: Select all
program Project2;
{$APPTYPE CONSOLE}
{$R-}{$S-}{$Q-}
uses
SysUtils;
type
point = record
x: integer;
y: integer;
end;
rect = record
x1: integer;
y1: integer;
x2: integer;
y2: integer;
end;
function pointInWin (const x,y: integer; const win: rect): boolean;
begin
pointInWin := ((x>=win.x1) and (y>=win.y1) and (x<=win.x2) and (y<=win.y2));
end;
function dist (const x1,y1,x2,y2: integer): integer;
begin
dist := round(sqrt(sqr(x1-x2)+sqr(y1-y2)))
end;
var
win: array ['A'..'Z'] of rect;
ico: array [1..100] of point;
i,j,k,l,m,ni,min: integer;
nc,c: char;
fl: boolean;
x,y: integer;
function iconOnTop (const x,y: integer): boolean;
var
c: char;
begin
for c:='A' to nc do
if pointInWin (x,y,win[c]) then
begin
iconOnTop := false;
exit
end;
iconOnTop := true
end;
begin
while not eof do
begin
nc := char(ord('A')-1);
ni := 0;
while true do
begin
read (c);
if c='I' then
begin
inc (ni);
readln (ico[ni].x,ico[ni].y);
end
else if c='R' then
begin
nc := char(ord(nc)+1);
readln (win[nc].x1,win[nc].y1,win[nc].x2,win[nc].y2)
end
else if c='M' then
begin
readln (x,y);
fl := false;
for c:=nc downto 'A' do
if pointInWin (x,y,win[c]) then
begin
writeln (c);
fl := true;
break
end;
min := 6000;
if fl then continue;
for i:=1 to ni do
if iconOnTop(ico[i].x,ico[i].y) and (dist(ico[i].x,ico[i].y,x,y) < min) then
min := dist(ico[i].x,ico[i].y,x,y);
if min <> 6000 then
for i:=1 to ni do
if (dist(ico[i].x,ico[i].y,x,y) = min) and iconOnTop (ico[i].x,ico[i].y) then
write (i:3);
writeln
end
else break;
end;
end;
end.
Thank you