I think my calculations are ok. But there may be any trick cause my program WA. please help.
- Suman
428 - Swamp County Roofs
Moderator: Board moderators
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
Why WA for 428?
This is really a simple question, but I keep getting WA.
Here is my code, what's wrong?
[cpp]#include<iostream>
#include<math.h>
using namespace std;
long double pi=2*acos(0);
long double roof(long double base,long double ridge,long double between){
return (base+ridge)*between/2;
}
int main(){
int case_no=0;
long double lot,thisroof,baseline,ridgeline,between,incline,roof_area,floor_area,total_roof=0,total_area=0,total_lot=0;
char bu;
cout<<"Roof Area Floor Area % Covered\n--------- ---------- ---------\n";
while(cin>>lot){
case_no++;
roof_area=0;
floor_area=0;
while(cin.peek()!='\n' && cin.peek()!=EOF){
cin>>baseline>>ridgeline>>between>>incline;
cin.get(bu);
thisroof=roof(baseline,ridgeline,between);
roof_area+=thisroof;
floor_area+=thisroof*cos(incline*pi/180.0);
}
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.width(9);
cout<<roof_area;
cout.width(15);
cout<<floor_area;
cout.width(13);
cout<<floor_area*100.0/lot<<"%\n";
total_roof+=roof_area;
total_area+=floor_area;
total_lot+=lot;
}
cout<<"\nTotal surface area of roofs";
cout.width(12);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<total_roof<<endl;
cout<<"Total area covered by roofs";
cout.width(12);
cout<<total_area<<endl<<"Percentage of total area covered by roofs";
cout.width(8);
cout<<total_area*100.0/total_lot<<"%\nAverage roof surface area per lot";
cout.width(16);
cout<<total_roof/case_no<<endl<<"Average floor space covered per lot";
cout.width(14);
cout<<total_area/case_no<<endl;
return 0;
}
[/cpp]
Here is my code, what's wrong?
[cpp]#include<iostream>
#include<math.h>
using namespace std;
long double pi=2*acos(0);
long double roof(long double base,long double ridge,long double between){
return (base+ridge)*between/2;
}
int main(){
int case_no=0;
long double lot,thisroof,baseline,ridgeline,between,incline,roof_area,floor_area,total_roof=0,total_area=0,total_lot=0;
char bu;
cout<<"Roof Area Floor Area % Covered\n--------- ---------- ---------\n";
while(cin>>lot){
case_no++;
roof_area=0;
floor_area=0;
while(cin.peek()!='\n' && cin.peek()!=EOF){
cin>>baseline>>ridgeline>>between>>incline;
cin.get(bu);
thisroof=roof(baseline,ridgeline,between);
roof_area+=thisroof;
floor_area+=thisroof*cos(incline*pi/180.0);
}
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.width(9);
cout<<roof_area;
cout.width(15);
cout<<floor_area;
cout.width(13);
cout<<floor_area*100.0/lot<<"%\n";
total_roof+=roof_area;
total_area+=floor_area;
total_lot+=lot;
}
cout<<"\nTotal surface area of roofs";
cout.width(12);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<total_roof<<endl;
cout<<"Total area covered by roofs";
cout.width(12);
cout<<total_area<<endl<<"Percentage of total area covered by roofs";
cout.width(8);
cout<<total_area*100.0/total_lot<<"%\nAverage roof surface area per lot";
cout.width(16);
cout<<total_roof/case_no<<endl<<"Average floor space covered per lot";
cout.width(14);
cout<<total_area/case_no<<endl;
return 0;
}
[/cpp]
-
- New poster
- Posts: 1
- Joined: Fri Oct 26, 2007 3:11 am
428 - Swamp County Roofs
I've been beating myself up about this problem because it's fairly easy but I keep getting the wrong answer. I believe it has to do with a simple case I'm not considering... If anyone could post some sample input for me to test, I'm sure I could find the problem and I would be much appreciative.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 428, WA...
Input:
AC output:
Code: Select all
100 10 10 10 60
10 10 10 60
200 5 10.5 5 30 10 10 7.5 45
100
10 10 10
60 10
10 10 60
200 5 10.5 5 30 10 10 7.5 45
100 0 10 7.5 45 10
0 7.5 -135
300
Code: Select all
Roof Area Floor Area % Covered
--------- ---------- ---------
200.00 100.00 100.00%
113.75 86.59 43.30%
0.00 0.00 0.00%
600.00 590.88 5908.85%
7701.25 7133.96 71339.57%
0.00 0.00 0.00%
Total surface area of roofs 8615.00
Total area covered by roofs 7911.43
Percentage of total area covered by roofs 1098.81%
Average roof surface area per lot 1435.83
Average floor space covered per lot 1318.57
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 139
- Joined: Wed May 18, 2011 3:04 pm
Re: 428 - Swamp County Roofs
The input format is not so friendly.
metaphysis: http://uhunt.onlinejudge.org/id/95895
My solutions for UVa problems: https://github.com/metaphysis/Code.
My solutions for UVa problems: https://github.com/metaphysis/Code.