2007-02-18

【Q476】 Points in Figures: Rectangles

題目:http://acm.uva.es/p/v4/476.html

說明:
  檢查平面座標上的點有沒有落在矩形裡面,要注意使用的變數型態!

程式下載:http://yaushung.googlepages.com/2007021802.c

程式:

#include <stdio.h>

int containTest(float r1_x, float r1_y, float r2_x, float r2_y, float p1, float p2) ;


int main() {
int rectangle = 0 ;
int count ;
int flag ;
int point_num = 1 ;
double r1_x[10], r1_y[10], r2_x[10], r2_y[10], p1, p2 ;
while(getchar() != '*') {
scanf("%lf %lf %lf %lf\n", &r1_x[rectangle], &r1_y[rectangle], &r2_x[rectangle], &r2_y[rectangle]) ;
rectangle++ ;
}
scanf("%lf %lf", &p1, &p2) ;
while(p1!=9999.9 p2!=9999.9) {
flag = 1 ;
for(count=0 ; count<rectangle ; count++) {
if(containTest(r1_x[count], r1_y[count], r2_x[count], r2_y[count], p1, p2)) {
printf("Point %d is contained in figure %d\n", point_num, count+1) ;
flag = 0 ;
}
}
if(flag)
printf("Point %d is not contained in any figure\n", point_num) ;
point_num++ ;
scanf("%lf %lf", &p1, &p2) ;
}
return 0 ;
}


int containTest(float r1_x, float r1_y, float r2_x, float r2_y, float p1, float p2) {
return (p1-r1_x)>0 && (r1_y-p2)>0 && (r2_x-p1)>0 && (p2-r2_y)>0 ;
}

沒有留言: