UVa 476 Points in Figures: Rectangles
解題:注意結束條件判斷
Code:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct triangle
{
double a,b,c,d;
};
bool cmp(triangle t,double x,double y)
{
if(x>t.a && y<t.b && x<t.c &&y>t.d) return true;
return false;
}
int main()
{
char ch=' ';
int ind=0;
triangle tri[10000];
while(cin>>ch&&ch!='*')
{
scanf("%lf %lf %lf %lf",&tri[ind].a,&tri[ind].b,&tri[ind].c,&tri[ind].d);
ind++;
}
int pind=1;
bool flag=false;
double x,y;
while(scanf("%lf%lf",&x,&y))
{
if(abs(x-9999.9) < 1e-9 &&abs(y-9999.-9) < 1e9) break;
flag=false;
for(int i=0; i<ind; i++)
{
if(cmp(tri[i],x,y))
{
printf("Point %d is contained in figure %d\n",pind,i+1);
flag=true;
}
}
if(!flag) printf("Point %d is not contained in any figure\n",pind);
pind++;
}
return 0;
}
留言
張貼留言