CF552-Div3-A. Restoring Three Numbers

Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c.

You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order.

Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c).

题意:给你三个数,这三个数分别是a+b,a+c,b+c,a+b+c(无序);求出a,b,c.(a>0,b>0,c>0)
题解:存进数组,sort以后,输出x4-x1,x4-x2,x4-x3(any order).x4是四个数中最大的数,可得出x4=a+b+c.那么其他三个数就是a+b,a+c,b+c.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int a[5];
	for(int i=1;i<=4;i++) cin>>a[i];
	sort(a+1,a+1+4);
	printf("%d %d %d\n",a[4]-a[1],a[4]-a[2],a[4]-a[3]);
	return 0;
}
posted @ 2019-04-18 00:35  _yjun  阅读(397)  评论(0编辑  收藏  举报