10137 - The Trip
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10137 - The Trip
Try solving it without using floating point.
The correct output is "$0.01". I updated:
http://www.udebug.com/UVa/10137
The correct output is "$0.01". I updated:
http://www.udebug.com/UVa/10137
Check input and AC output for thousands of problems on uDebug!
10137 - The Trip
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;
}
#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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10137 - The Trip
brianfry713 wrote:Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!
Re: 10137 - The Trip
Someone please help me!! what problems with my code ? why I got WA?
delete code after AC
delete code after AC
Last edited by stevesJ03 on Wed Nov 12, 2014 4:53 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10137 - The Trip
brianfry713 wrote:brianfry713 wrote:Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!
Re: 10137 - The Trip
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 10137 - The Trip
thanks, I get AClighted wrote:http://www.algorithmist.com/index.php/UVa_10137
![:D](./images/smilies/icon_biggrin.gif)
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 10137 - The Trip
Why I am getting WA with my bellow code?
Code: Select all
Accepted
Last edited by Shahidul.CSE on Thu Dec 11, 2014 5:58 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Re: 10137 - The Trip
Try to check input in this thread before posting.
brianfry713 wrote:Input:AC output: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
Code: Select all
$0.01
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 10137 - The Trip
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;
}
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
Last edited by brianfry713 on Wed Aug 19, 2015 8:51 pm, edited 1 time in total.
Reason: Added code block
Reason: Added code block