We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 05bb5f5 commit 9d2f289Copy full SHA for 9d2f289
1 file changed
Problems/Mathematics/Day-01/sol/Priyanshi_Giri/question1.cpp
@@ -0,0 +1,40 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+
4
+int main() {
5
+ ios_base::sync_with_stdio(false);
6
+ cin.tie(NULL);
7
8
+ int t;
9
+ cin >> t;
10
+ while (t--) {
11
+ int a, b, c;
12
+ cin >> a >> b >> c;
13
+ int n = 2*(abs(a-b));
14
15
+ if(a == b){
16
+ cout << -1 << endl;
17
+ continue;
18
+ }
19
20
+ if(a > n || b > n || c > n){
21
22
23
24
25
+ if(c + (n/2) <= n){
26
+ cout << (c+(n/2)) << endl;
27
+ }else{
28
+ cout << (c-(n/2)) << endl;
29
30
31
32
+ return 0;
33
+}
34
35
36
37
38
+/* Explaination : The opposite numbers must be having exactly n/2 numbers in between, hence the total number, ie. n = 2*abs(a-b).
39
40
+Time Complexity : O(t), t is the number of test cases. */
0 commit comments