-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContest0.java
More file actions
44 lines (39 loc) · 1.14 KB
/
Contest0.java
File metadata and controls
44 lines (39 loc) · 1.14 KB
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
package techgig;
import java.util.Scanner;
public class Contest0 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number of judges (n): ");
int n = scanner.nextInt();
if(n == 0) {
System.out.println("Total score = 0");
} else if(n > 0 && n < 20 && n % 2 != 0) {
System.out.println("Enter max score (m): ");
int m = scanner.nextInt();
int[] scores = new int[n];
for(short i = 0; i < n; i++) {
do {
System.out.println("Enter " + (i + 1) + " judge score: ");
scores[i] = scanner.nextInt();
} while(scores[i] < 0 || scores[i] > m);
}
System.out.println("Total = " + calculateTotal(scores));
} else {
System.out.println("Entered wrong number of judges");
}
}
private static int calculateTotal(int[] scores) {
int total = 0, nextL = 0, nextR = 0;
int midPoint = (int) Math.floor(scores.length/2);
total += scores[midPoint];
nextL = midPoint - 1;
nextR = midPoint + 1;
while(nextL >= 0 && nextR < scores.length) {
if(scores[nextL] == scores[nextR]) {
total += scores[nextL];
}
nextL--; nextR++;
}
return total;
}
}