朱色虫居
Pages
Home
Featured Posts
2006/09/09
477-Points in Figures: Rectangles and Circles
/*
"Points in Figures: Rectangles and Circles"
Level:3.5
Date:2006/9/8
技巧:
長方形的判斷: x > 左上角的x && x < 右下角的x && y < 左上角的y && y > 右下角的y
圓形的判斷: (x - 圓心的x)^2 + (y - 圓心的y)^2 < 半徑^2 */ #include
struct shape{
char kind; //rectangle or circle
double x1;
double y1;
double x2;
double y2;
double radius;
}s[10];
main(){
int i;
int no=1;
bool contain = false;
int len = 0;
double x,y;
char temp;
double distance;
while(scanf("%c",&temp)){
if(temp == 'r'){
scanf("%lf %lf %lf %lf",&s[len].x1,&s[len].y1,
&s[len].x2,&s[len].y2);
s[len].kind = 'r';
s[len].radius = 0;
len++;
}
else if (temp == 'c'){
scanf("%lf %lf %lf", &s[len].x1, &s[len].y1, &s[len].radius);
s[len].kind = 'c';
s[len].x2 = s[len].y2 = 0;
len++;
}
else if(temp == '*')
break;
}
while(scanf("%lf %lf",&x,&y)){
if(x == 9999.9 && y == 9999.9)
break;
for(i=0;i
s[i].x1 && x < s[i].x2 && y < s[i].y1 && y > s[i].y2){
printf("Point %d is contained in figure %d\n",no,i+1);
contain = true;
}
else if (s[i].kind == 'c' && (x-s[i].x1)*(x-s[i].x1)+(y-s[i].y1)*(y-s[i].y1)
< s[i].radius * s[i].radius){ printf("Point %d is contained in figure %d\n",no,i+1); contain = true; } } if(contain == false) printf("Point %d is not contained in any figure\n",no); no++; contain = false; } }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment