Posted: Wed Jul 12, 2006 2:28 pm
make ur s[10][4] array double.
Code: Select all
// Q476 Points in figure: Rectangles
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(int argc, char *argv[])
{
int tmp;
double ar[100][4];
char c; // indicate r or *
for(int i = 1; ; i++)
{
cin >> c;
if(c == 'r')
{
cin >> ar[i][0] >> ar[i][1] >> ar[i][2] >> ar[i][3];
if(ar[i][0] > ar[i][2])
swap(ar[i][0],ar[i][2]);
if(ar[i][3] > ar[i][1])
swap(ar[i][3],ar[i][1]);
}
else
{
tmp = i;
break;
}
} // process the data of rectangle
bool k;
int index = 1;
double n, m;
while(cin >> n >> m)
{
if(n == 9999.9 && m == 9999.9)
break;
k = false;
for(int i = 1; i < tmp; i++)
{
if((n > ar[i][0] && n < ar[i][2]) && (m > ar[i][3] && m < ar[i][1]))
{
cout << "Point " << index++ << " is contained in figure " << i << endl;
k = true;
break;
}
}
if(k == false)
cout << "Point " << index++ << " is not contained in any figure\n";
}
system("PAUSE");
return EXIT_SUCCESS;
}
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct
{
float x1, x2, y1, y2;
int indeks;
}
rec;
typedef struct
{
float x, y, r;
int indeks;
}
cir;
typedef struct
{
float x, y;
}
fig;
int main()
{
rec rectangle[100];
fig figure[4000];
cir circular[1000];
char shape;
int indeks2 = 0;
int i, j = 0;
int counter;
char x[1000], y[1000];
while(scanf("%c", &shape))
{
if(shape=='*') break;
else if(shape=='r')
{
scanf("%f %f %f %f", &rectangle[j].x1, &rectangle[j].y1, &rectangle[j].x2, &rectangle[j].y2);
rectangle[j].indeks = j;
j++;
}
else if(shape=='c')
{
scanf("%f %f %f", &circular[j].x, &circular[j].y, &circular[j].r);
circular[j].indeks = j;
j++;
}
}
while(scanf("%s %s", x, y))
{
if(strcmp(x, "9999.9")==0 && strcmp(y, "9999.9")==0 ) break;
figure[indeks2].x = atof(x);
figure[indeks2].y = atof(y);
counter= 0;
for(i=0;i<j;i++)
{
if(rectangle[i].indeks == i)
{
if(figure[indeks2].x>rectangle[i].x1 && figure[indeks2].x < rectangle[i].x2 && figure[indeks2].x && figure[indeks2].y < rectangle[i].y1 && figure[indeks2].y > rectangle[i].y2)
{
printf("Point %d is contained in figure %d\n", indeks2+1, i+1);
counter = 1;
}
}
else
{
if( pow ( abs ( figure[indeks2].x - circular[i].x ) , 2 ) + pow ( abs ( figure[indeks2].y - circular[i].y ), 2) < pow( circular[i].r , 2) )
{
printf("Point %d is contained in figure %d\n", indeks2+1, i+1);
counter = 1;
}
}
}
if(counter==0) printf("Point %d is not contained in any figure\n", indeks2);
indeks2++;
}
return 0;
}
helloneo wrote:Do not create a new thread if there is one already..
http://online-judge.uva.es/board/viewtopic.php?t=13384
sorry..helloneo wrote:I meant "new topic" by that..
helloneo wrote:Hmm.. I didn't say about how to solve it..
Use old topics.. did you go to the link I mentioned above..?