Do You Know Your ABCs?#10364

Do You Know Your ABCs? (Editorial)

Sort all seven input numbers. The two smallest ones correspond to the values of and . The largest number in the list represents the sum a + b + c. Subtracting and from it gives the value of .

Example

Sort the input numbers.

We have: a = 2, b = 2. Since a + b + c = 11, then c = 11 - a - b = 11 - 2 - 2 = 7.

Algorithm implementation

Read the seven input numbers into an array.

for (i = 0; i < 7; i++)
  scanf("%d", &nums[i]);

Sort the array.

sort(nums, nums + 7);

The two smallest numbers correspond to the values of and .

a = nums[0], b = nums[1];

The largest number in the array equals a + b + c. Subtracting and from it gives .

c = nums[6] - a - b;

Print the answer.

printf("%d %d %d\n", a, b, c);