The RRCODE program runs without error on my personal computer. What causes Ada to produce the NZEC error on CodeChef?
The code is:
– Code Chef Problem RRCode –
with Ada.Text_Io; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;
with Ada.Command_Line; use Ada.Command_Line;
procedure RRCODE is
type Data is mod 10**9 + 1;
subtype Index is Positive range 1…1000;
subtype T is Positive range 1…100;
type Data_Array is array(Index range <>) of Data;
type operations is (a, o, x);
Package Data_IO is new Ada.Text_IO.Modular_IO(Data);
use Data_IO;
function F (N : in Index;
K : in Data;
Answer : in Data;
Operator : in Operations;
The_Data : in Data_Array) return Data is
Temp : Data := Answer;
begin
for I in 1…K loop
for J in The_Data’Range loop
case Operator is
when a =>
Temp := Temp and The_Data(J);
when o =>
Temp := Temp or The_Data(J);
when x =>
Temp := Temp xor The_Data(j);
end case;
end loop;
end loop;
return Temp;
end F;
Tries : T;
N : Index;
K : Data;
Answer : Data;
Operator_String : String(1…10);
Operator_Length : Natural;
Opcode : Operations;
begin
Get(Item => Tries);
for Try in 1…Tries loop
Get(Item => N);
Get(Item => K);
Get(Item => Answer);
declare
The_Data : Data_Array(1…N);
begin
for I in The_Data’Range loop
Get(Item => The_Data(I));
end loop;
Skip_Line;
Get_Line(Item => Operator_String, Last => Operator_Length);
if Operator_String(1) = ‘A’ then
Opcode := a;
elsif Operator_String(1) = ‘O’ then
Opcode := o;
else
Opcode := x;
end if;
Put_Line(Data’Image(F(N, K, Answer, Opcode, The_Data)));
end;
end loop;
Set_Exit_Status(Code => Success);
end RRCODE;