Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
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;
}