French mathematician Melzziac proposed a question in his famous "digital combination game" (1962): a businessman has a weight 40 pound weight, and accidentally falls the weight into four. Later, businessmen weighted the weight of each piece, and found that the four pieces of debris can be called any weight between 1 to 40 pounds on the balance. How much is these four pieces of debris?
* Question analysis and algorithm design
The conditions given in the topic are "on the balance", which means that the same weight can be placed on the left side of the balance, or it can be placed on the right side of the balance. If the specified weight can only be placed on the left side of the balance, there is a flat balance on the day:
Heavy weight left weight sum total = right weight weight sum
Therefore:
Heavy weight = right weight weight sum - the weight of the left weight weight
When programming, as long as the above formula is based on the above formula, "the weight of the weight of the right side", the weight of the left side can represent all weights between 1 and 40. It should be noted in the program: how to use a simple method to indicate that a weight is on the left side of the balance or on the right side of the balance, or is not used at all.
The following procedures indicate the above three cases, respectively, please note.
* Program and Program Note #include