SlideShare a Scribd company logo
From Skiena and Revilla, Programming Challenges: The Programming Contest Training Manual
Springer-Verlag, New York, 2003. ISBN: 0-387-00163-8
110103 The Trip
A group of students are members of a club that travels annually to different locations. Their
destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and
Atlanta. This spring they are planning a trip to Eindhoven.
The group agrees in advance to share expenses equally, but it is not practical to share every expense
as it occurs. Thus individuals in the group pay for particular things, such as meals, hotels, taxi rides,
and plane tickets. After the trip, each student’s expenses are tallied and money is exchanged so that
the net cost to each is the same, to within one cent. In the past, this money exchange has been tedious
and time consuming. Your job is to compute, from a list of expenses, the minimum amount of money
that must change hands in order to equalize (within one cent) all the students’costs.
Input
Standard input will contain the information for several trips. Each trip consists of a line containing
a positive integer n denoting the number of students on the trip. This is followed by n lines of input,
each containing the amount spent by a student in dollars and cents. There are no more than 1000
students and no student spent more than $10,000.00. A single line containing 0 follows the information
for the last trip.
Output
For each trip, output a line stating the total amount of money, in dollars and cents, that must be
exchanged to equalize the students’costs.
Sample Input
3
10.00
20.00
30.00
4
15.00
15.01
3.00
3.01
0
Sample Output
$10.00
$11.99
http://www.programming-challenges.com copyright c 2003

More Related Content

Viewers also liked

Direitos autorais
Direitos autoraisDireitos autorais
Direitos autorais
guiguiass
 
What's the color of your diet?
What's the color of your diet?What's the color of your diet?
What's the color of your diet?
Hungry Bells
 
Com2u s 4q14_eng
Com2u s 4q14_engCom2u s 4q14_eng
Com2u s 4q14_eng
GameBizInside
 
kamal kant dewan.
kamal kant dewan.kamal kant dewan.
kamal kant dewan.
Sham Kaushal
 
Tech Hardware Releases: October
Tech Hardware Releases: OctoberTech Hardware Releases: October
Tech Hardware Releases: October
Owler
 
Image Inspirtation
Image InspirtationImage Inspirtation
Image Inspirtation
lucyallbutmedia
 
Media Roles Pricing Guide
Media Roles Pricing GuideMedia Roles Pricing Guide
Media Roles Pricing Guide
Tom_Adams
 
Branding
BrandingBranding
Branding
Indira
 
Homework+2
Homework+2Homework+2
Homework+2
mattieamayesing
 

Viewers also liked (9)

Direitos autorais
Direitos autoraisDireitos autorais
Direitos autorais
 
What's the color of your diet?
What's the color of your diet?What's the color of your diet?
What's the color of your diet?
 
Com2u s 4q14_eng
Com2u s 4q14_engCom2u s 4q14_eng
Com2u s 4q14_eng
 
kamal kant dewan.
kamal kant dewan.kamal kant dewan.
kamal kant dewan.
 
Tech Hardware Releases: October
Tech Hardware Releases: OctoberTech Hardware Releases: October
Tech Hardware Releases: October
 
Image Inspirtation
Image InspirtationImage Inspirtation
Image Inspirtation
 
Media Roles Pricing Guide
Media Roles Pricing GuideMedia Roles Pricing Guide
Media Roles Pricing Guide
 
Branding
BrandingBranding
Branding
 
Homework+2
Homework+2Homework+2
Homework+2
 

More from Sudipta Mukherjee

Sudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta_Mukherjee_Resume-Nov_2022.pdfSudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta Mukherjee
 
Sudipta mukherjee certificate
Sudipta mukherjee certificateSudipta mukherjee certificate
Sudipta mukherjee certificate
Sudipta Mukherjee
 
Sudipta mukherjee 2016_2017
Sudipta mukherjee 2016_2017Sudipta mukherjee 2016_2017
Sudipta mukherjee 2016_2017
Sudipta Mukherjee
 
Think in linq
Think in linqThink in linq
Think in linq
Sudipta Mukherjee
 
Sudipta_Mukherjee_2016_2017
Sudipta_Mukherjee_2016_2017Sudipta_Mukherjee_2016_2017
Sudipta_Mukherjee_2016_2017
Sudipta Mukherjee
 
Coursera ml 2016
Coursera ml 2016Coursera ml 2016
Coursera ml 2016
Sudipta Mukherjee
 
Squirrel – Enabling Accessible Analytics for All
Squirrel – Enabling Accessible Analytics for AllSquirrel – Enabling Accessible Analytics for All
Squirrel – Enabling Accessible Analytics for All
Sudipta Mukherjee
 
Squirrel do more_with_less_code_light_cheatsheet
Squirrel do more_with_less_code_light_cheatsheetSquirrel do more_with_less_code_light_cheatsheet
Squirrel do more_with_less_code_light_cheatsheet
Sudipta Mukherjee
 
Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_cheat_sheet_1Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_cheat_sheet_1
Sudipta Mukherjee
 
Sudipta mukherjee
Sudipta mukherjeeSudipta mukherjee
Sudipta mukherjee
Sudipta Mukherjee
 
Thinking in linq
Thinking in linqThinking in linq
Thinking in linq
Sudipta Mukherjee
 
Functional programming (Let's fall back in love with Programming)
Functional programming (Let's fall back in love with Programming)Functional programming (Let's fall back in love with Programming)
Functional programming (Let's fall back in love with Programming)
Sudipta Mukherjee
 
C sharp fsharp_pain_pleasure_1
C sharp fsharp_pain_pleasure_1C sharp fsharp_pain_pleasure_1
C sharp fsharp_pain_pleasure_1
Sudipta Mukherjee
 

More from Sudipta Mukherjee (13)

Sudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta_Mukherjee_Resume-Nov_2022.pdfSudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta_Mukherjee_Resume-Nov_2022.pdf
 
Sudipta mukherjee certificate
Sudipta mukherjee certificateSudipta mukherjee certificate
Sudipta mukherjee certificate
 
Sudipta mukherjee 2016_2017
Sudipta mukherjee 2016_2017Sudipta mukherjee 2016_2017
Sudipta mukherjee 2016_2017
 
Think in linq
Think in linqThink in linq
Think in linq
 
Sudipta_Mukherjee_2016_2017
Sudipta_Mukherjee_2016_2017Sudipta_Mukherjee_2016_2017
Sudipta_Mukherjee_2016_2017
 
Coursera ml 2016
Coursera ml 2016Coursera ml 2016
Coursera ml 2016
 
Squirrel – Enabling Accessible Analytics for All
Squirrel – Enabling Accessible Analytics for AllSquirrel – Enabling Accessible Analytics for All
Squirrel – Enabling Accessible Analytics for All
 
Squirrel do more_with_less_code_light_cheatsheet
Squirrel do more_with_less_code_light_cheatsheetSquirrel do more_with_less_code_light_cheatsheet
Squirrel do more_with_less_code_light_cheatsheet
 
Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_cheat_sheet_1Squirrel do more_with_less_code_cheat_sheet_1
Squirrel do more_with_less_code_cheat_sheet_1
 
Sudipta mukherjee
Sudipta mukherjeeSudipta mukherjee
Sudipta mukherjee
 
Thinking in linq
Thinking in linqThinking in linq
Thinking in linq
 
Functional programming (Let's fall back in love with Programming)
Functional programming (Let's fall back in love with Programming)Functional programming (Let's fall back in love with Programming)
Functional programming (Let's fall back in love with Programming)
 
C sharp fsharp_pain_pleasure_1
C sharp fsharp_pain_pleasure_1C sharp fsharp_pain_pleasure_1
C sharp fsharp_pain_pleasure_1
 

110103

  • 1. From Skiena and Revilla, Programming Challenges: The Programming Contest Training Manual Springer-Verlag, New York, 2003. ISBN: 0-387-00163-8 110103 The Trip A group of students are members of a club that travels annually to different locations. Their destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and Atlanta. This spring they are planning a trip to Eindhoven. The group agrees in advance to share expenses equally, but it is not practical to share every expense as it occurs. Thus individuals in the group pay for particular things, such as meals, hotels, taxi rides, and plane tickets. After the trip, each student’s expenses are tallied and money is exchanged so that the net cost to each is the same, to within one cent. In the past, this money exchange has been tedious and time consuming. Your job is to compute, from a list of expenses, the minimum amount of money that must change hands in order to equalize (within one cent) all the students’costs. Input Standard input will contain the information for several trips. Each trip consists of a line containing a positive integer n denoting the number of students on the trip. This is followed by n lines of input, each containing the amount spent by a student in dollars and cents. There are no more than 1000 students and no student spent more than $10,000.00. A single line containing 0 follows the information for the last trip. Output For each trip, output a line stating the total amount of money, in dollars and cents, that must be exchanged to equalize the students’costs. Sample Input 3 10.00 20.00 30.00 4 15.00 15.01 3.00 3.01 0 Sample Output $10.00 $11.99 http://www.programming-challenges.com copyright c 2003