Fotolog

A través del espejo
2010-10-12: A través del espejo
¡La radio habla en binario!
2010-10-10: ¡La radio habla en binario!
Gigaminx (regalo por mi cumple)
2010-09-16: Gigaminx (regalo por mi cumple)
Trini en bici
2010-09-05: Trini en bici
Valporquero
2010-08-28: Valporquero
Mi bici nueva
2010-08-22: Mi bici nueva
Boda de Mario y Ana
2010-08-13: Boda de Mario y Ana
De cañones en Guara
2010-08-07: De cañones en Guara
Trini y Mari en Marbella
2010-08-05: Trini y Mari en Marbella
Trini y Chelo en Tabarca
2010-08-03: Trini y Chelo en Tabarca
Valid XHTML 1.1
Acceder
Volver a la lista de problemas

Points in Figures: Rectangles

476.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;
}