var i,l,k,n,p:integer;
s:string;
Z: set of char;
A: array[1..100] of real;
B: array[1..100] of char;
R,Buf:real;
function F(A:real; Z:char; B:real):real;
begin
case Z of
'+': result:=A+B;
'-': result:=A-B;
'*': result:=A*B;
'/': result:=A/B;
end;
end;
begin
Assign(input,'input.txt');
Assign(output,'output.txt');
Reset(input);
Rewrite(output);
Readln(S);
close(input);
L:=length(s);
k:=0;
n:=0;
Z:=['+','-','*','/'];
for i:=1 to L do
if not(S[i] in Z) then begin
inc(k);
A[k]:=StrToInt(S[i]);
end
else begin
inc(n);
B[n]:=S[i];
end;
if (S[1] in Z) then
begin
if s[1]='-' then A[1]:=A[1]*(-1);
for i:=1 to n do
b[i]:=b[i+1];
dec(n);
end;
i:=0;
While (i begin
inc(i);
if ((B[i]= '*') or (B[i]='/')) then
begin
buf:=F(A[i],B[i],A[i+1]);
A[i]:=buf;
for p:=i+1 to k do
A[p]:=A[p+1];
for p:=i to n do
B[p]:=B[p+1];
dec(n);
dec(i);
end;
end; R:=A[1];
for i:=1 to n do
if not((B[i]= '*') or (B[i]='/')) then
R:=F(R,B[i],A[i+1]);
writeln(R);
Close(output);
end.
Скачать вложение Текст (TXT)
Скачать вложение Текст (TXT)