Page 11 of 11
Re: 10137 - The Trip
Posted: Mon Sep 08, 2014 8:42 pm
by brianfry713
Try solving it without using floating point.
The correct output is "$0.01". I updated:
http://www.udebug.com/UVa/10137
10137 - The Trip
Posted: Wed Sep 17, 2014 8:34 am
by abccoder
i got wrong answer.What's problem on my below code?
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int i;
long n;
double sum,c[1001],avg,pay,receive;
while(scanf("%ld",&n)>0)
{
sum=0.0;
pay,receive=0.0;
for(i=0;i<n;i++)
{
cin>>c;
sum+=c;
}
avg=(long)(sum/n);
for(i=0;i<n;i++)
{
if(avg>c)
{
pay+=avg-c;
}
else{
receive+=c-avg;
}
}
receive=-receive;
if(pay>receive)
cout<<"$"<<pay<<endl;
else
cout<<"$"<<receive<<endl;
}
return 0;
}
Re: 10137 - The Trip
Posted: Wed Sep 17, 2014 7:43 pm
by brianfry713
brianfry713 wrote:Try solving it without using floating point.
Re: 10137 - The Trip
Posted: Tue Nov 11, 2014 7:01 pm
by stevesJ03
Someone please help me!! what problems with my code ? why I got WA?
delete code after AC
Re: 10137 - The Trip
Posted: Tue Nov 11, 2014 8:47 pm
by brianfry713
brianfry713 wrote:brianfry713 wrote:Try solving it without using floating point.
Re: 10137 - The Trip
Posted: Wed Nov 12, 2014 7:30 am
by lighted
Re: 10137 - The Trip
Posted: Wed Nov 12, 2014 3:44 pm
by stevesJ03
thanks, I get AC

Re: 10137 - The Trip
Posted: Thu Dec 11, 2014 8:11 am
by Shahidul.CSE
Why I am getting WA with my bellow code?
Re: 10137 - The Trip
Posted: Thu Dec 11, 2014 3:00 pm
by lighted
Try to check input in this thread before posting.
brianfry713 wrote:Input:
Code: Select all
21
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.01
0.03
0
AC output:
Re: 10137 - The Trip
Posted: Thu Aug 13, 2015 9:11 am
by mac07
Code: Select all
//C++ Source
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
int students, counter=0;
double payments[1000], total=0, deficits[1000], surplus[1000];
while(1)
{
cin >> students;
total = 0;
if (students == 0)
{
for (int i=0; i<counter; i++)
{
if (deficits[i] < surplus[i]) deficits[i] = surplus[i]; //line 14
cout << '$' << setprecision(2) << fixed << deficits[i] << endl;
}
return 0;
}
for (int i=0; i<students; i++) {cin >> payments[i]; total+= payments[i];}
total /= students;
deficits[counter] = 0;
surplus[counter] = 0;
for (int i=0; i<students; i++)
if (payments[i] < total) deficits[counter] += (floor((total - payments[i])*100))/100;//line 28
else if (payments[i] > total) surplus[counter] += (floor((-total + payments[i])*100))/100; //line 29
counter++;
}
return 0;
}
In line 14, why do we want that if statement? And in line 28 & 29, why do we round off the difference ?
Also, I didnt understand this part "After the trip,each student's expenses are tallied and money is exchanged so that net cost to the each is same,to within one cent".
to within one cent?
Can someone please explain these?
Please help