function min(a, b: integer): integer;
begin
case a>b
of
true: result := b;
false: result := a;
end;
end;
function max(a, b: integer): integer;
begin
case a<b
of
true: result := b;
false: result := a;
end;
end;
function allAway(Rch:
string):
string;
var
b, e, i: integer;
begin
Rch := '
' + rch + '
';
while max(pos('
*', rch), pos('
/', rch)) > 0
do begin
i := min(pos('
*', rch), pos('
/', rch));
if pos('
*', rch) = 0
then
i := pos('
/', rch);
if pos('
/', rch) = 0
then
i := pos('
*', rch);
b := i-1;
e := i+1;
while rch[b-1]
in ['
0'..'
9']
do dec(b);
while rch[e+1]
in ['
0'..'
9']
do inc(e);
if rch[i]
in ['
*', '
/']
then begin
case Rch[i]
of
'
*': insert(IntToStr(StrToInt(copy(rch, b, i - b)) * StrToInt(copy(rch, i + 1, e - i))), rch, e+1);
'
/': insert(IntToStr(StrToInt(copy(rch, b, i - b))
div StrToInt(copy(rch, i + 1, e - i))), rch, e+1);
end;
delete(rch, b, e - b + 1);
end;
end;
result := copy(rch, 2, length(rch) - 2);
end;