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).

Input
The only line of the input contains four positive integers x1,x2,x3,x4 (2≤xi≤109) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number x1,x2,x3,x4.

Output
Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

Examples
inputCopy
3 6 5 4
outputCopy
2 1 3
inputCopy
40 40 40 60
outputCopy
20 20 20
inputCopy
201 101 101 200
outputCopy
1 100 100

题目思路:输入进去sort排序,最后一个分别减前三个,然后输出

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
using namespace std;

struct node {
	ll rng;
	ll edg;
	ll lgd;
	ll sng;
}S[100005];

int main() {
	ll a[5];
	while (cin >> a[0]) {
		for(ll i = 1; i < 4; i++) {
			cin >> a[i];
		}
		sort(a, a + 4);
		ll x, y, z;
		x = a[3] - a[2];
		y = a[3] - a[1];
		z = a[3] - a[0];
		cout << x << " " << y << " " << z << endl;
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_44231195/article/details/89344668