-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTemplate.java
50 lines (42 loc) · 1.03 KB
/
Template.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
48
49
50
import java.io.*;
import java.util.*;
public class Template {
public static void main(String[] args) throws Exception {
String name = "A-small";
String path = "";
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(new File(path + name + ".in"));
PrintWriter pw = new PrintWriter(path + name + ".out");
// Scanner sc = new Scanner(System.in);
// PrintWriter pw = new PrintWriter(System.out);
int testCases = sc.nextInt();
for (int testCase = 1; testCase <= testCases; testCase++) {
String cmd = sc.next();
int n = sc.nextInt();
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextDouble();
}
final double res;
switch (cmd) {
case "median":
Arrays.sort(a);
res = a[n / 2];
break;
case "mean":
double sum = 0;
for (double v : a) {
sum += v;
}
res = sum / n;
break;
default:
throw new RuntimeException();
}
pw.printf("Case #" + testCase + ": %.10f\n", res);
pw.flush();
}
pw.close();
sc.close();
}
}