Sunday, February 27, 2011

476- Points in Figures: Rectangles


#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    char type[20],inp[2000];
    register int i=0,p,pc=0,n;
    double x,y,x1[20],y1[20],x2[20],y2[20],a,b,c,d;
    //freopen("in.txt","r",stdin);
    while(1)
    {
        gets(inp);
        sscanf(inp,"%s%lf%lf%lf%lf",type,&a,&b,&c,&d);
        if(type[0]=='*')break;
        x1[i]=a,y1[i]=b,x2[i]=c,y2[i]=d;
        i++;
    }
    n=i;
    while(1)
    {
        gets(inp);
        sscanf(inp,"%lf%lf",&x,&y);
        if(x==9999.9&&y==9999.9)break;
        p=0,pc++;
        for(i=0;i<n;i++)
        {
            if(x>x1[i]&&x<x2[i]&&y>y2[i]&&y<y1[i])
            {
                p=1;
                printf("Point %d is contained in figure %d\n",pc,i+1);
            }
        }
        if(!p)printf("Point %d is not contained in any figure\n",pc);
    }
    return 0;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.