i don't think there is any `exception' in this problem... i just got it accepted at first try... so you better check your code again.. tell us if you still got problem...
Greetings
class Main
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}
void Begin()
{
String input;
StringTokenizer idata;
float x,y;
float [][] matrix=new float [10][4];
int numOfRec=0;
int numOfPoint=0;
int loop;
String temp;
boolean ifBeCon;
while ((input = Main.ReadLn (255)) != null)
{
numOfPoint++;
idata = new StringTokenizer (input);
ifBeCon=false;
x=Float.parseFloat (idata.nextToken());
y=Float.parseFloat (idata.nextToken());
if((x==9999.9)&&(y==9999.9)) break;
for(loop=0;loop<numOfRec;loop++)
{
if((x>matrix[loop][0])&&(x<matrix[loop][2])&&(y<matrix[loop][1])&&(y>matrix[loop][3]))
{
ifBeCon=true;
System.out.println("Point "+numOfPoint+" is contained in figure "+(loop+1));
}
}
if(ifBeCon==false)
System.out.println("Point "+numOfPoint+" is not contained in any figure");
}
}
}[/java][/java]
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
it Give's WA i don't no what is wrong.help please.
[pascal]program acm476;
label 1,2;
var a,a1,a2,a3:array[1..10000] of real;
number,i,j,k,n:integer;
c:char;
b,bb:real;
t:boolean;
begin
while not eof do
begin
i:=0;
repeat
read(c);
i:=i+1;
if c='*' then goto 1;
readln(a,a1,a2,a3)
until 1=2;
1: n:=i;
number:=0;
repeat
number:=number+1;
read(b);
readln(bb);
if (b=9999.9) and (bb=9999.9) then goto 2;
t:=false;
for i:=1 to n do
if (b>=a) and (b<=a2) and (bb<=a1) and (bb>=a3) then begin t:=true;
writeln('Point ',number,' is contained in figure ',i) end;
if t=false then writeln('Point ',number,' is not contained in any figure');
until 1=2;
2:
end;
end.[/pascal]
it gives WA help please i really don't know what is wrong
[pascal]program acm476;
label 1,2;
var a:array[1..4,1..100] of real;
x,y:real;
i,j,k,n,number:longint;
c:char;
procedure solve(x,y:real;number:longint);
var i,j,k:longint;
t:boolean;
begin
t:=false;
for i:=1 to n do
begin
if
(x>a[1,i]) and
(x<a[3,i]) and
(y<a[2,i]) and
(y>a[4,i]) then
begin
t:=true;
writeln('Point ',number,' is contained in figure ',i);
end;
end;
if t=false then writeln('Point ',number,' is not contained in any figure');
end;
begin
i:=0;
repeat
read(c);
if c='*' then goto 1;
if c='r' then
begin
i:=i+1;
for j:=1 to 4 do
read(a[j,i]);
end;
until 1=2;
1: n:=i;
number:=0;
repeat
number:=number+1;
readln(x,y);
if (x=9999.9) and (y=9999.9) then goto 2;
solve(x,y,number);
until 1=2;
2:
end.[/pascal]
Hi mohiul,
You do not have to create an array and fill it up to create a rectangle.. This problem is easy. keep an array like you are keeping and when a pt is given just compare if the point lies in bound..
Eg. l=left r=right t=top b=bottom x,y is the point
if(x>l && x<r && y>b && y<t) cout<<"In figure";
if it fails for all figures then it obviously does not lie in any figure....
I hope it answers any doubts you have about the problem...
flag=0;
for(i=0;i<num;i++){
if((p1x>(a.left))&&(p1x<(a.right))&&
(p1y>(a.bottom))&&(p1y<(a.top)))
{
flag=1;
printf("Point %ld is contained in figure %ld\n",p,i+1);
}
}
if(flag==0)
printf("Point %ld is not contained in any figure\n",p);
}
return 0;
}[/cpp][/code]