Posted: Sat Mar 10, 2007 6:22 pm
If you got AC, remove you code plz.. 

Code: Select all
#include <stdio.h>
#include <string.h>
struct rect{
long double upp_left_x;
long double upp_left_y;
long double low_right_x;
long double low_right_y;
};
struct fig{
long double x;
long double y;
};
char c;
int main()
{
rect array[100];
int i = 1,k = 1;
int flag,j;
long double x,y;
while(1)
{
scanf("%c",&c);
if(c == '*')
break;
scanf("%Lf %Lf %Lf %Lf",&array[i].upp_left_x,&array[i].upp_left_y,&array[i].low_right_x,&array[i].low_right_y);
i++;
fflush(stdin);
}
while(scanf("%Lf %Lf",&x,&y)==2)
{
if(x == 9999.9 && y == 9999.9)
break;
flag = 1;
for(j = 1;j <= i;j++)
{
if((x > array[j].upp_left_x && x < array[j].low_right_x ) && ( y < array[j].upp_left_y && y > array[j].low_right_y))
{
printf("Point %d is contained in figure %d\n",k,j);
flag = 0;
}
}
if(flag)
printf("Point %d is not contained in any figure\n",k);
k++;
}
return 0;
}
Code: Select all
0.0 0.0
2.5 2.5
12.5 12.5
Code: Select all
Point 1 is contained in figure 2
Point 2 is contained in figure 2
Point 2 is contained in figure 3
Point 3 is contained in figure 1
Point 3 is contained in figure 3
Code: Select all
Point 1 is not contained in any figure
Point 2 is contained in figure 2
Point 3 is contained in figure 1
Code: Select all
#include <stdio.h>
int main()
{
float x[10][2],y[10][2];
int i=0;
char r;
while(i<10)
{
scanf("%c",&r);
if(r=='*')
break;
else if(r=='r')
{
scanf("%f %f %f %f",&x[i][0],&y[i][0],&x[i][1],&y[i][1]);
i++;
}
}
double x1,y1;
int cout=1,judge=0;
int j=0;
while(scanf("%lf %lf",&x1,&y1)==2)
{
if(x1 >= 9999.9 && y1 >= 9999.9)
break;
for(j=0,judge=0;j<i;j++)
{
if(x1>x[j][0] && x1<x[j][1] &&y1>y[j][1] && y1<y[j][0] )
{
printf("Point %d is contained in figure %d\n",cout,(j+1));
judge=1;
}
}
if(judge==0 && x1!=9999.9)
{
printf("Point %d is not contained in any figure\n",cout);
}
cout++;
}
return 0;
}
Code: Select all
if(judge==0 && x1!=9999.9)
Code: Select all
if (fabs(x1-9999.9)<EPS)
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,flag,c;
double reacA[12][2],reacB[12][2],x,y;
char str[5];
for(i=0,c=0;i<10;i++)
{
scanf("%s",str);
if (strcmp(str,"*")==0) break;
c++;
if(strcmp(str,"r")==0) scanf("%lf %lf %lf %lf",&reacA[i][0],&reacA[i][1],&reacB[i][0],&reacB[i][1]);
}
for(j=0;;j++)
{
scanf("%lf %lf",&x,&y);
if(x==9999.9 && y==9999.9) break;
flag=0;
for(i=0;i<c;i++)
{
if(x>reacA[i][0] && x< reacB[i][0] && y<reacA[i][1] && y>reacB[i][1])
{
printf("Point %d is contained in figure %d\n",j+1,i+1);
flag=1;
}
}
if(flag==0)
printf("Point %d is not contained in any figure\n",j+1);
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <math.h>
int main()
{
double gr[13][6], x, y;
int i, j, k, m, f;
char ch;
i = 0;
while(scanf("%c", &ch) == 1){
if(ch == '*') break;
if(ch == 'r'){
for(j = 0; j < 4; j++){
scanf("%lf", &gr[i][j]);
}
i++;
}
}
m = i;
for(k = 0;; k++){
scanf("%lf %lf", &x, &y);
if(x == 9999.9 && y == 9999.9) break;
f = 0;
for(i = 0; i < m; i++){
if((x >= gr[i][0] && x <= gr[i][2]) && (y >= gr[i][3] && y <= gr[i][1])){
printf("Point %d is contained in figure %d\n", k+1, i+1);
f = 1;
}
}
if(f == 0) printf("Point %d is not contained in any figure\n", k+1);
}
return 0;
}
Post in existing threads. Don't open new thread. Use search by problem number 476.Points coinciding with a figure border are not considered inside