Photolog
Back to list of problems
Points in Figures: Rectangles and Circles
477.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct figure {
char type;
double a, b, c, d;
};
int num_figures = 0;
struct figure figures[12];
int
main(void) {
int i;
int point=1;
while (1) {
char t;
scanf(" %c", &t);
figures[num_figures].type=t;
if (t=='r') {
scanf("%lf %lf %lf %lf",
&figures[num_figures].a,
&figures[num_figures].b,
&figures[num_figures].c,
&figures[num_figures].d);
} else if (t=='c') {
scanf("%lf %lf %lf",
&figures[num_figures].a,
&figures[num_figures].b,
&figures[num_figures].c);
} else if (t=='*') {
break;
} else {
abort();
}
num_figures++;
}
while (1) {
int done=0;
double x, y;
scanf("%lf %lf", &x, &y);
if (x>9999.89 && x<9999.91 && y>9999.89 && y<9999.91) {
return 0;
}
for (i=0; i<num_figures; i++) {
if (figures[i].type=='r') {
if (x>figures[i].a && x<figures[i].c && y>figures[i].d && y<figures[i].b) {
printf("Point %d is contained in figure %d\n", point, i+1);
done=1;
}
} else { /* circle */
if (sqrt((x-figures[i].a)*(x-figures[i].a) + (y-figures[i].b)*(y-figures[i].b)) < figures[i].c) {
printf("Point %d is contained in figure %d\n", point, i+1);
done=1;
}
}
}
if (!done) {
printf("Point %d is not contained in any figure\n", point);
}
point++;
}
return 0;
}









