# 点在哪里

 Sample input Output for the input r 0.0 0.0 5.5 10.3 c -5.0 -5.0 3.7 r 2.5 2.5 12.5 12.5 * 2.0 2.0 4.7 5.3 9999.9 9999.9 Point 1 is contained in figure 1 Point 2 is contained in figure 1 Point 2 is contained in figure 3

 Sample input Output for the input r 8.5 -8.5 25.5 17.0 c 20.2 7.3 5.8 r 0.0 0.0 5.5 10.3 c -5.0 -5.0 3.7 r 2.5 2.5 12.5 12.5 c 5.0 15.0 7.2 * 6.9 11.2 20.0 20.0 17.6 3.2 -5.2 -7.8 4.7 5.3 2.0 2.0 9999.9 9999.9 Point 1 is contained in figure 5 Point 1 is contained in figure 6 Point 2 is not contained in any figure Point 3 is contained in figure 1 Point 3 is contained in figure 2 Point 4 is contained in figure 4 Point 5 is contained in figure 3 Point 5 is contained in figure 5 Point 6 is contained in figure 3

.

#include < stdio.h >
#include
< math.h >
#include
< string .h >
#include
< stdlib.h >

#define  MAXLEN 1000
#define  RGET(TYPE,VAR,LOC) ((TRectangle *)TYPE[LOC].data)->VAR
#define  CGET(TYPE,VAR,LOC) ((TCircle *)TYPE[LOC].data)->VAR

struct  TRectangle {    //矩形
float x1,x2,y1,y2;
}
;

struct  TCircle {    //
float x,y,r;
}
;

class  Figure {
public:

void *data;

char type;    //type='r' 表示矩形；type='c' 表示圆
}
;

int  figlen;
Figure figure[MAXLEN];

inline
void
swap(
float   & a, float   & b) {    //交换a和b的值
float c;
c
=a;
a
=b;
b
=c;
}

inline
bool
equal(
const   float  a, const   float  b) //判断俩浮点数是否相等
return fabs(a-b)<1e-6;
}

inline
void
{    //读取图形数据
char type;

while(1){
type
=getchar();

if(type=='*'return;
figure[figlen].type
=type;

if(type=='r'){
figure[figlen].data
=new TRectangle;
scanf(
"%f%f%f%f",&RGET(figure,x1,figlen),&RGET(figure,y1,figlen),&RGET(figure,x2,figlen),&RGET(figure,y2,figlen));
figlen
++;
}

else if(type=='c'){
figure[figlen].data
=new TCircle;
scanf(
"%f%f%f",&CGET(figure,x,figlen),&CGET(figure,y,figlen),&CGET(figure,r,figlen));
figlen
++;
}

}

}

inline
void
caculate()
{    //输入点并输出所在图形
float a,b,c,d;

int i,no=0;

bool ok;

while(1){
scanf(
"%f%f",&a,&b);

if(equal(a,9999.9f&& equal(b,9999.9f)) return;

++no;
ok
=false;

for(i=0;i<figlen;i++)

if(figure[i].type=='r'){

if(RGET(figure,x1,i)<&& RGET(figure,x2,i)>&& RGET(figure,y1,i)<&& RGET(figure,y2,i)>b){
printf(
"Point %d is contained in figure %d ",no,i+1);
ok
=true;
}

}

else{
c
=CGET(figure,x,i)-a;
c
*=c;
d
=CGET(figure,y,i)-b;
d
*=d;

if(sqrt(c+d)<CGET(figure,r,i) || equal((float)sqrt(c+d),CGET(figure,r,i))){
printf(
"Point %d is contained in figure %d ",no,i+1);
ok
=true;
}

}

if(ok==false) printf("Point %d is not contained in any figure ",no);
}

}

void
main()
{

int fd;
fd
=open("test.txt",O_RDONLY);
dup2(fd,
0);
fd
=open("result.txt",O_TRUNC|O_WRONLY);
dup2(fd,
1);
figlen
=0;