Дан файл F. Вывести на экран лишь строки с соответствием открытых и закрытых скобок — Pascal(Паскаль)

uses
  crt;
var
  f:text;
  s:string;
{функция проверки на открытие закрытие скобок}
function Skobki(s: string):boolean;
var
  i,temp:integer;
begin
  temp:= 0;
  for i:=1 to length(s) do
  begin
    if s[i]='(' then
      dec(temp);
    if s[i]=')' then
      inc(temp)
  end;
  if temp=0 then
    Result:=true
  else
    Result:=false
end;
{основная программа}
begin
  clrscr;
  assign(F, '1.txt');
  reset(f);
  while not eof(f) do
  begin
    readln(f,s);
    if Skobki(s) then
      writeln(s)
  end;
  close(f);
end.

Leave a Comment

18 − 15 =