Цитата:
Сообщение от Kot_Bayun
Проблема с написанием программы. Помогите, прошу, иначе лабы сдать не смогу и вылечу из ВУЗа
|
Да ладно, живите:
Код:
Var
Q:Array[1..100] of Word;
R:Array[1..100] of Real;
T:Array[1..100] of Char;
S,P:String;
i,j,Code,N:Word;
Function Sign(W:Char):boolean;
begin
Sign:=(W='*') or (W='/') or (W='+') or (W='-');
end;
Begin
Writeln('Enter the string:');
Readln(S);
N:=0;
i:=0;
Repeat
P:='';
Repeat
Inc(i);
If Not Sign(S[i]) then P:=P+S[i];
Until Sign(S[i]) or (i=Length(S));
Inc(N);
Val(P,Q[N],Code);
if i<Length(S) then T[N]:=S[i];
Until i=Length(S);
for i:=1 to N do R[i]:=Q[i];
Repeat
i:=0;
Repeat
Inc(i);
Until (T[i]='*') or (T[i]='/') or (i=N-1);
if (T[i]='*') or (T[i]='/') then
begin
if T[i]='*' then R[i]:=R[i]*R[i+1] else R[i]:=R[i]/R[i+1];
for j:=i+1 to N-1 do R[j]:=R[j+1];
for j:=i to N-2 do T[j]:=T[j+1];
Dec(N);
end;
Until i>N-1;
Repeat
i:=0;
Repeat
Inc(i);
Until (T[i]='+') or (T[i]='-') or (i>=N-1);
if (T[i]='+') or (T[i]='-') then
begin
if T[i]='+' then R[i]:=R[i]+R[i+1] else R[i]:=R[i]-R[i+1];
for j:=i+1 to N-1 do R[j]:=R[j+1];
for j:=i to N-2 do T[j]:=T[j+1];
Dec(N);
end;
Until i>N-1;
Writeln(R[1]:0:5);
Readln
End.