-
Notifications
You must be signed in to change notification settings - Fork 1
/
rough.js
35 lines (28 loc) · 890 Bytes
/
rough.js
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
const readline = require('readline/promises');
const { stdin: input, stdout: output } = require('process');
async function main() {
const rl = readline.createInterface({ input, output });
// Taking integer input for number of iterations
let x = parseInt(await rl.question(''));
while (x--) {
let a, b, c;
// Taking multiple inputs
const line = await rl.question('');
[a, b, c] = line.split(' ').map(Number);
if (a + b == c) {
console.log(c);
} else if (a == b && b == c) {
if (a % 2 == 0) {
console.log(c);
} else {
console.log(-1);
}
} else if (a + b > c) {
console.log((c) + (a + b-c)/2);
} else {
console.log(a+b);
}
}
rl.close();
}
main();