
Prac_parentheses
By:
t1nman on
May 28th, 2012 | syntax:
Pascal | size: 1.31 KB | hits: 27 | expires: Never
uses UStack;
procedure Inp(var somestack: Stack);
var
ifp: Text;
parenthesis: char;
begin
assign(ifp,'input.txt');
reset(ifp);
read(ifp,parenthesis);
while (parenthesis <> '.') do
begin
somestack.push(parenthesis);
read(ifp,parenthesis);
end;
close(ifp);
end;
procedure Outp(somestack: Stack);
var
ofp: Text;
tmp: Stack;
null: char;
flag: boolean;
begin
tmp.Init;
flag:= TRUE;
while not (somestack.isEmpty) do
begin
if (somestack.top = ')') then
tmp.push(somestack.pop)
else
begin
null:= somestack.pop;
if (tmp.isEmpty) then
begin
flag:= FALSE;
break;
end
else
null:= tmp.pop;
end;
end;
assign(ofp,'output.txt');
rewrite(ofp);
if ((flag) and (tmp.isEmpty)) then
writeln(ofp, 'TRUE')
else
writeln(ofp, 'FALSE');
close(ofp);
end;
var
mystack: Stack;
begin
writeln;
mystack.Init;
writeln('start reading from file...');
Inp(mystack);
writeln('...finished'); writeln;
writeln('start writing to file...');
Outp(mystack);
writeln('...finished'); writeln;
end.