Skip to content

Instantly share code, notes, and snippets.

@Yi-Tseng
Created September 24, 2012 15:05
Show Gist options
  • Save Yi-Tseng/3776428 to your computer and use it in GitHub Desktop.
Save Yi-Tseng/3776428 to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef struct{
float x;
float y;
}point;
typedef struct{
point ul;
point lr;
}rect;
int contain(point p,rect r){
if(r.ul.x < p.x && p.x < r.lr.x){
if(r.lr.y < p.y && p.y < r.ul.y){
return 1;
}
}
return 0;
}
int main(int argc, const char * argv[])
{
char head;
rect rects[11];
int num_rects = 0;
while(scanf("%c",&head)){
if(head == '*'){
break;
}else if(head == '\n'){
continue;
}
scanf("%f",&(rects[num_rects].ul.x));
scanf("%f",&(rects[num_rects].ul.y));
scanf("%f",&(rects[num_rects].lr.x));
scanf("%f",&(rects[num_rects].lr.y));
num_rects++;
}
float x,y;
int num_points = 0;
while(scanf("%f%f",&x,&y)){
if(x == 9999.9f && y == 9999.9f){
break;
}
point p;
p.x = x;
p.y = y;
num_points ++;
int num_cont = 0;
int c;
for(c=0;c<num_rects;c++){
if(contain(p, rects[c]) == 1){
num_cont++;
printf("Point %d is contained in figure %d\n",num_points,c+1);
}
}
if(num_cont == 0){
printf("Point %d is not contained in any figure\n",num_points);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment