Learn Computer Programming Here ... and maybe represent Ireland?
You are not logged in.
Trevor's table has finally collapsed! He had been piling books, boxes and computer hardware onto it for years, and just yesterday, the left leg of the table splintered, causing a big mess.
He now wants to replace the leg with something tougher, so goes to the local quarry to get some stone blocks. Unfortunately, Trevor can only afford two blocks, and must find two such blocks so that the sum of their sizes adds up to exactly one metre (1000mm), since the other table leg is this height. The quarry has a long list of all the sizes of the stone blocks they currently have on sale.
Write a computer program to help Trevor find two blocks whos sizes sum to 1000. If there are multiple solutions, choose the solution where the size of largest stone is minimised.
E.g. 100 & 900 is a solution, and 400 & 600 is also a solution, but 400&600 is better because 600<900.
Example input:
How many stones are in the quarry? 10
What are the sizes of the 10 stones? 200 250 401 708 358 100 150 330 999 850
Example output:
Trevor should buy a size 150 and a size 850
Offline
Do we assume that there is a solution in every input?
Offline
Hi Paul,
if your program does not find a solution, you can print a message such as "No two blocks can be found to sum to 1000".
Ciarán.
Offline
Do we assume that there can be an infinite number of stones in the quarry?
Offline
Hi,
well you can assume all sizes will be positive integers, which means there is only a finite number of relevant sizes to consider.
Offline
hi all members.. i just joined this forums....hope that i find this forum as great community...
Offline