Tuesday, August 26, 2014

COJ 1237. Mean Median Problem

There are only 3 cases possible
1. (A+B+C)/3=A
2. (A+B+C)/3=B
3. (A+B+C)/3=C

from each we can get
1. C=2*A-B
2. C=2*B-A
3. C=(A+B)/2

You can make a function which checks the answer for 3 numbers and run it 3 times on all of the cases above and pick the minimum.


       FULL SOURCE CODE

No comments:

Post a Comment