I am trying to submit a code on Codeforces, but I always get compilation errors. My computer does just fine. Here is the code:
var s, tmp: ansistring;
i, j, c: integer;
function elim(var s: ansistring): ansistring;
var i: integer;
begin
elim:='';
for i:=1 to length(s) do
begin
if s[i]='(' then elim:=elim+s[i]
else if elim[length(elim)]='(' then delete(elim, length(elim), 1);
end;
end;
begin
readln(s); tmp:=elim(s); c:=0;
if (tmp<>'((') and (tmp<>'))') then writeln(0)
else if tmp='((' then
begin
i:=0; s:=s+'0';
while (s[i+1]='(') and (s[i+2]=')') do i:=i+2;
for j:=i+2 to length(s) do
if s[j]='(' then c:=c+1;
writeln(c);
end
else begin
i:=length(s)+1; s:='0'+s;
while (s[i-2]='(') and (s[i-1]=')') do i:=i-2;
for j:=i-2 downto 1 do
if s[j]=')' then c:=c+1;
writeln(c);
end;
end.
And here are the comp errors:
Invocation failed [COMPILATION_ERROR]
Can't compile file:
Target OS: Win32 for i386
Compiling program.pas
program.pas(11,36) Error: Operator is not overloaded: "elim(var AnsiString):AnsiString;" + "Char"
program.pas(12,22) Error: Illegal qualifier
program.pas(12,22) Error: Type mismatch
program.pas(12,58) Error: Type mismatch
program.pas(34,4) Fatal: There were 4 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\Programs\FPC\bin\i386-Win32\ppc386.exe returned an error exitcode
It seems that Codeforces' FPC does not allow adding char and string. How do I resolve this?
P.S. I use FPC 3.0.4.