-
Notifications
You must be signed in to change notification settings - Fork 3
/
CompareTheTriplets.java
47 lines (39 loc) · 1.23 KB
/
CompareTheTriplets.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
// https://www.hackerrank.com/challenges/compare-the-triplets/problem
package warmup;
import java.util.Arrays;
import java.util.Scanner;
public class CompareTheTriplets {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
Score alice = getScore();
Score bob = getScore();
int[] result = alice.compareWith(bob);
System.out.println(result[0] + " " + result[1]);
}
private static Score getScore() {
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
return new Score(a, b, c);
}
private static class Score {
int[] array = new int[3];
Score(int a, int b, int c) {
array[0] = a;
array[1] = b;
array[2] = c;
}
int[] compareWith(Score score) {
int me = 0;
int other = 0;
for (int index = 0 ; index < 3 ; index++) {
if (array[index] > score.array[index]) {
me++;
} else if (array[index] < score.array[index]) {
other++;
}
}
return new int[] {me, other};
}
}
}