## 10137 - The Trip

Moderator: Board moderators

brianfry713
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
Check input and AC output for thousands of problems on uDebug!

abccoder
New poster
Posts: 2
Joined: Mon Sep 15, 2014 1:30 pm

### 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;
while(scanf("%ld",&n)>0)
{
sum=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{
}

}
cout<<"\$"<<pay<<endl;
else
}
return 0;
}

brianfry713
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!

stevesJ03
New poster
Posts: 5
Joined: Tue Nov 11, 2014 6:50 pm

### Re: 10137 - The Trip

delete code after AC
Last edited by stevesJ03 on Wed Nov 12, 2014 4:53 pm, edited 1 time in total.

brianfry713
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!

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### 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

stevesJ03
New poster
Posts: 5
Joined: Tue Nov 11, 2014 6:50 pm

### Re: 10137 - The Trip

thanks, I get AC

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Contact:

### 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
Email me: shahidul.cse.brur@gmail.com

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10137 - The Trip

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:

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

mac07
New poster
Posts: 1
Joined: Wed Aug 12, 2015 3:37 pm

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

``````
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?