## 476 - Points in Figures: Rectangles

Moderator: Board moderators

sunny
Experienced poster
Posts: 124
Joined: Sun Sep 11, 2005 10:22 pm
Location: Civil-BUET
make ur s array double.

pin0512
New poster
Posts: 2
Joined: Tue Jul 11, 2006 3:36 pm
Contact:

### thanks

thank you,i edit and got AC

Carunty
New poster
Posts: 18
Joined: Sat Jul 08, 2006 2:40 am

### 476 WA

I dont know why it is WA. Can anyone help me?
Here is my code.

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
int c=1; double y,z; char x; vector<vector<double> > v;
while(cin >> x,x!='*'){
vector<double> w;
for(int i=0;i<4;cin>>y,w.push_back(y),++i);
v.push_back(w);
}
while(cin >> y >> z){
if(y==9999.9&&z==9999.9) break;
int i;
for(i=0;i<v.size();++i) if(v<y&&y<v&&v>z&&z>v) break;
if(i==v.size()) cout << "Point " << c << " is not contained in any figure" << endl;
else cout << "Point " << c << " is contained in figure " << i+1 << endl;
++c;
}
}

Bluefin
New poster
Posts: 20
Joined: Sat Jul 08, 2006 3:39 pm
Contact:

### WA Q476

I don't know why I get so many WA on this easy question. I have read all the thread on Q476, but none of them solved my problem. Can anyone give me a hand ???

Every suggestion is appreciated !!! Here's my code:

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;
char c;    // indicate r or *
for(int i = 1; ; i++)
{
cin >> c;
if(c == 'r')
{
cin >> ar[i] >> ar[i] >> ar[i] >> ar[i];
if(ar[i] > ar[i])
swap(ar[i],ar[i]);
if(ar[i] > ar[i])
swap(ar[i],ar[i]);
}
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] && n < ar[i]) && (m > ar[i] && m < ar[i]))
{
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;
}
``````
"It's nice to be important, but it's more important to be nice"

http://bluefintuna.wordpress.com/

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
Please post in one of the 20+ threads that exist for this problem, and don't create a new one.

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:
i got runtime error.. dun know why.. help plz

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;
fig figure;
cir circular;
char shape;
int indeks2 = 0;
int i, j = 0;
int counter;
char x, y;

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;
}
``````

max566
New poster
Posts: 3
Joined: Fri Dec 22, 2006 5:16 pm

### acm 476 runtime error(Signal 11)

Here is my code.
I try a lot of times.
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

float str_to_float(string &s)
{
int count=0;
string temp;
double i_num,f_num,result;
for(int i=0;i < int(s.size());++i)
{
++count;
if(s=='.')
break;
}
temp = s.substr(0,count-1);
istringstream (temp) >> i_num;
string _temp = s.substr(count,s.size()-count);
istringstream (temp) >> f_num;
while(f_num >=1 && f_num !=0)
f_num /= 10;
result = i_num + f_num;
return result;
}

void input_coordinate(char *shape,float *r_x,float *r_y)
{
for(int i=0;i<20;i+=2)
{
cin >> shape;
if(shape=='*')
break;
cin >> r_x >> r_y >> r_x[i+1] >> r_y[i+1];
}
}

int input_test_coordinate(float *a, float *b)
{
string str_1,str_2;
int count=0;
for(int i=0;;i++)
{
cin >> str_1 >> str_2;
if(str_1 !="9999.9" && str_2 !="9999.9")
{
a = str_to_float(str_1);
b = str_to_float(str_2);
}
else
break;
count++;
}
return count;
}

int main(int argc, char *argv[])
{
char shape={0};
float rec_x={0},rec_y={0};
input_coordinate(shape,rec_x,rec_y);
float *x=new float;
float *y=new float;
int count=input_test_coordinate(x,y);
for(int j=0;j<count;++j)
{
bool test=0;
int figure_num=1;
for(int i=0;i<20;i+=2)
{
if(x[j] > rec_x && x[j] < rec_x[i+1] && y[j] <rec_y && y[j] > rec_y[i+1])
{
test = true;
cout << "Point " << j+1 << " is contained in figure " << figure_num << endl;
}
figure_num++;
}
if(test == false)
cout << "Point " << j+1 << " is not contained in any figure" << endl;
}
return 0;
}

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Search your problem in the forum first. If you find a thread use it. Otherwise open a new one.
Ami ekhono shopno dekhi...
HomePage

New poster
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am

### acm 476 runtime error(Signal 11)

plz tell me where is the problem??

here is my c-code
thank you very much Last edited by deadhunter411 on Sun Mar 11, 2007 6:37 pm, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

http://online-judge.uva.es/board/viewtopic.php?t=13384

New poster
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am

### thx first

helloneo wrote:Do not create a new thread if there is one already..

http://online-judge.uva.es/board/viewtopic.php?t=13384

Sorry. I'm Taiwanese.so..
I don't know the "thread" means.
Can you explan it?
thank you very much!!

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
I meant "new topic" by that.. New poster
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am
helloneo wrote:I meant "new topic" by that.. sorry.. I still can't understand how to solve the error...

new topic???
can you give me an example?

thank you.. helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Hmm.. I didn't say about how to solve it..

Use old topics.. did you go to the link I mentioned above..?

New poster
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am
helloneo wrote:Hmm.. I didn't say about how to solve it..

Use old topics.. did you go to the link I mentioned above..?

thank you for help struct testp point;
to
struct testp point;

than get AC...