-
Notifications
You must be signed in to change notification settings - Fork 10
/
template.d
49 lines (39 loc) · 1.02 KB
/
template.d
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
import std.stdio;
import std.string;
import std.algorithm;
void main() {
string name = "A-small";
string path = "";
File input = File(path ~ name ~ ".in", "r");
File output = File(path ~ name ~ ".out", "w");
int testCases;
input.readf(" %d", &testCases);
foreach(testCase; 1..testCases + 1) {
string cmd;
int n;
input.readf(" %s %d", &cmd, &n);
double[] a = new double[](n);
foreach(i; 0..n) {
input.readf(" %f", &a[i]);
}
double res;
switch (cmd) {
case "median":
a.sort();
res = a[n / 2];
break;
case "mean":
double s = 0;
foreach(i; 0..n) {
s += a[i];
}
res = s / n;
break;
default:
throw new Exception("");
}
output.writefln("Case #%d: %.10f", testCase, res);
}
output.close();
input.close();
}