2 Checker for NEERC'2009 Problem J: Java Certification
\r
16 n: array[1..100] of integer;
17 w: array[1..100] of integer;
25 p: array[1..100] of integer;
\r
27 function rint(a: double): integer;
\r
32 if (abs(abs(res - a) - 0.5) < 1e-9) then begin
\r
33 if (res mod 2 = 1) then begin
\r
34 if (res > a) then res := res - 1 else res := res + 1;
\r
40 procedure readoutput(var res: output; var strm: InStream; isPA: boolean);
42 i, s, min, max, pp: integer;
44 for i := 1 to m do begin
45 res.w[i] := strm.readlongint;
46 res.n[i] := strm.readlongint;
48 if (res.n[i] < 1) or (res.n[i] > 100) then
49 quit(_WA, format('Invalid number of questions: %d, must be 1..100', [res.n[i]]));
50 if (res.w[i] < 0) or (res.w[i] > res.n[i]) then
51 quit(_WA, format('Invalid number of wrong answers: %d, must be 0..%d', [res.w[i], res.n[i]]));
56 for i := 1 to m do begin
59 if (s <> nn) then quit(_WA, format('Wrong sum of questions: %d, must be %d', [s, nn]));
61 for i := 1 to m do begin
62 s := s + (res.n[i] - res.w[i]);
64 if (s <> kk) then quit(_WA, format('Wrong sum of correct answers: %d, must be %d', [s, kk]));
65 for i := 1 to m do begin
66 pp := rint(100 * (res.n[i] - res.w[i]) / res.n[i]);
67 if (pp <> p[i]) then quit(_WA, format('Wrong percentage for category %d: %d instead of %d', [i, pp, p[i]]));
72 for i := 1 to m do begin
\r
73 if (res.n[i] < min) then min := res.n[i];
\r
74 if (res.n[i] > max) then max := res.n[i];
\r
76 res.res := max - min;
\r
84 kk := inf.readlongint;
\r
85 nn := inf.readlongint;
\r
88 p[i] := inf.readlongint;
90 readoutput(pa, ouf, true);
91 readoutput(ja, ans, false);
93 if (pa.res > ja.res) then quit(_WA, format('Not optimal soluton: %d instead of %d', [pa.res, ja.res]));
\r
94 if (pa.res < ja.res) then quit(_FAIL, format('Jury solution is not optimal: %d instead of %d', [pa.res, ja.res]));
\r