import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(bufferedReader.readLine());
int b = Integer.parseInt(bufferedReader.readLine());
int c = Integer.parseInt(bufferedReader.readLine());
double average = (a + b +c)/3.0;
double a2 = Math.abs(a - average);
double b2 = Math.abs(b - average);
double c2 = Math.abs(c - average);
double d = Math.min(a2, b2);
double e = Math.min(d, c2);
if (e == a2) {
System.out.println(a);
} else if (e == b2) {
System.out.println(b);
} else if (e == c2) {
System.out.println(c);
}
}
}
Hello, I'd like to ask why my code below was validated as wrong (task 0441). I could not find any drawbacks when testing :( Thanks.
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
7 April 2021, 03:46
try your code with entering:
-1192214040, -807212768, -781535924
The middle number of those three would be: -807212768
The problem is that adding three ints together will only work if they do not add up to over the max or less than the min value allowed by an int. If the sum is greater/less than that, even by 1, the whole calculation will be thrown off.
0
Ondrej Sulc
7 April 2021, 19:26
Guadalupe, thank you very much, I'll try it.
0