476 - Points in Figures: Rectangles
Moderator: Board moderators
thanks
thank you,i edit and got AC
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[0]<y&&y<v[2]&&v[1]>z&&z>v[3]) 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;
}
}
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[0]<y&&y<v[2]&&v[1]>z&&z>v[3]) 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;
}
}
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:
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[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;
}
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
-
- 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[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;
}
acm 476 runtime error(Signal 11)
Here is my code.
I try a lot of times.
But I can't get AC.Please help.Thanks
#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[10]={0};
float rec_x[20]={0},rec_y[20]={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;
}
I try a lot of times.
But I can't get AC.Please help.Thanks
#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[10]={0};
float rec_x[20]={0},rec_y[20]={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;
}
Search your problem in the forum first. If you find a thread use it. Otherwise open a new one.
Ami ekhono shopno dekhi...
HomePage
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
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.
Do not create a new thread if there is one already..
http://online-judge.uva.es/board/viewtopic.php?t=13384
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!!
-
- New poster
- Posts: 8
- Joined: Sat Mar 10, 2007 10:20 am
-
- New poster
- Posts: 8
- Joined: Sat Mar 10, 2007 10:20 am