Дан текстовый файл f, содержащий программу на языке Паскаль. Проверить эту программу на несоответствие числа открывающих и закрывающих круглых скобок — Pascal(Паскаль)

uses crt;
var i,k:integer;
f:boolean;
st:string;
ff:text;
 
begin
 clrscr;
 k:=0;
 f:=true;
 assign(ff,'text.txt');
 reset(ff);
 while (not eof(ff)) and f do
 begin
  readln(ff,st);
  for i:=1 to length(st) do if st[i]='(' then k:=k+1 else if st[i]=')' then
  begin
   k:=k-1;
   if k<0 then
   begin
    f:=false;
    break;
   end;
  end;
 end;
 close(ff);
 if f and (k=0) then write('CORRECT') else write('INCORRECT');
 readln;
end.

Leave a Comment

1 + 1 =