-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestoring_Three_Numbers.cpp
More file actions
43 lines (37 loc) · 1.42 KB
/
Copy pathRestoring_Three_Numbers.cpp
File metadata and controls
43 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*Restoring Three Numbers
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int a[4];
for(int i=0;i<4;i++){
cin>>a[i];
}
sort(a,a+4);
cout<<a[3]-a[2]<<" "<<a[3]-a[1]<<" "<<a[3]-a[0];
return 0;
}