const
MAX = 20;
var
s:string;
stack:array[1..MAX] of string;
top:integer;
i:byte;
procedure Push(ch:string);
begin
if top>=MAX then WriteLn('Stask full')
else
begin
stack[top]:=ch;
top:=top+1;
end;
end;
function Pop:string;
begin
top:=top-1;
if top<1 then
begin
WriteLn('Stack underflow');
top:=top+1;
end
else Pop := stack[top];
end;
begin
top:=1;
s:='<asdf<asdf>asdf>';//правильная строка
for i:=1 to length(s) do
begin
if s[i]='<' then Push('<');
if s[i]='>' then
if Pop()<>'<' then WriteLn('Ошибка!');
end;
if top<>1 then WriteLn('Ошибка!');
top:=1;
s:='<asdf<asdfasdf>';//не правильная строка
for i:=1 to length(s) do
begin
if s[i]='<' then Push('<');
if s[i]='>' then
if Pop()<>'<' then WriteLn('Ошибка!');
end;
if top<>1 then WriteLn('Ошибка!');
end.
Объяснение:
Program ToDec;
Uses crt;
var s:string;
n,l,i:integer;
function Pow(x,y:integer):integer;
begin
if y>0 then Pow:=Pow(x,y-1)*x
else Pow:=1;
end;
function ToDec(A : string) : integer;
var L : Byte;
begin
if A = '' then ToDec := 0
else begin
L := length(A);
case A[1] of
'0' : ToDec := ToDec(Copy(A, 2, L - 1));
'1' : ToDec := Pow(2, L - 1) + ToDec(Copy(A, 2, L - 1));
end;
end;
end;
begin
clrscr;
write('Введите двоичное число: ');
readln(s);
writeln('Это число в десятичной системе : ', ToDec(S));
readkey;
end.