-
Notifications
You must be signed in to change notification settings - Fork 0
/
Temperatures.java
47 lines (39 loc) · 977 Bytes
/
Temperatures.java
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
44
45
46
47
/*
* Author: Robin Péricé (2018)
*/
package solutions.practice.classicPuzzles.easy;
import java.util.Scanner;
class Temperatures {
public static void main(final String args[]) {
final Scanner in = new Scanner(System.in);
final int n = in.nextInt();
in.nextLine();
final String temps = in.nextLine();
System.err.println(temps);
int result = 0;
boolean firstResult = true;
if (n != 0) {
final String[] tempsList = temps.split(" ");
for (final String tmp : tempsList) {
final int current = Integer.valueOf(tmp);
final int currentAbs = Math.abs(current);
if (firstResult) {
firstResult = false;
result = current;
} else {
if (Math.abs(result) == currentAbs) {
if (current > 0) {
result = current;
}
} else {
final int t = Math.min(Math.abs(result), currentAbs);
if (t < Math.abs(result)) {
result = current;
}
}
}
}
}
System.out.println(result);
}
}