Stamps II X68780


Statement
 

pdf   zip   main.cc

html

We want to send a postcard by mail. We need to stamp worth n cents (n≥ 20). Stamps have values 7 and 4 cents. As space is limited we want to know the minimum number of stamps we need to put on the postcard, without losing a cent.

Using the definition

struct Stamps { int stamp7; int stamp4; };

implement a recursive function

Stamps min_stamps(int n)

computing the mimimum number of necessary worth 7 stamps (stamp7 field) and worth 4 stamps (stamp4 field) for a total worth of n cents (n ≥ 20). For instance, for n = 58, the result fields of min_stamps must be 6 and 4.

Observation In order to complete the recursive case, note that recursive calls will always provide a Stamps tuple with stamp4 field at most 6.

Observation This problem is an example about using tuples in order to define functions computing a result that does not have a default representation as a single value.

Observation You only need to submit the required classes; your main program will be ignored. Strictly obey the type definitions of the statement.

Information
Author
Jorge Castro
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
Unknown. This problem is being checked.
User solutions
C++