Что делать?
!!!!Все написано в Паскале!!!!
Программа:
Код
program postf;
uses
PostUnit, Crt;
var
s:string;
l:longint;
begin
ClrScr;
Writeln('Vvedite postficsalnoe viragenie (primer: "10 15 + 2 * 10 / 5 +" otvet: 10; pisat bez kavichek) ');
s:='';
ReadLn(s);
Stroka(s,l);
Writeln(l);
Readkey;
end.
uses
PostUnit, Crt;
var
s:string;
l:longint;
begin
ClrScr;
Writeln('Vvedite postficsalnoe viragenie (primer: "10 15 + 2 * 10 / 5 +" otvet: 10; pisat bez kavichek) ');
s:='';
ReadLn(s);
Stroka(s,l);
Writeln(l);
Readkey;
end.
Модуль:
Код
Unit PostUnit;
interface
Type
Ukaz=^ stek;
Stek = record
num1:longint;
next:Ukaz;
end;
Var
top,P:Ukaz;
procedure AddStek(znak:longint);
procedure DelStek;
procedure obrabotka(dey:integer);
procedure Stroka(str:string; result:longint);
implementation
{procedure AddStek(znak:longint);}
procedure AddStek;
begin
New(P);
P^.num1:=znak;
P^.Next:=top;
top:=P;
end;
procedure DelStek;
begin
P:=top;
top:=top^.Next;
Dispose(P);
end;
{procedure obrabotka(dey:integer);}
procedure obrabotka;
var
N:integer;
begin
if dey=1 then { + }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=N+P^.num1;
end
else
if dey=2 then { - }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=N-P^.num1;
end
else
if dey=3 then { * }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=N*P^.num1;
end
else
if dey=4 then { / }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=round(N/P^.num1);
end;
DelStek;
{ DelStek;}
AddStek(N);
end;
{procedure Stroka(str:string; result:longint);}
procedure Stroka;
var
code,i:integer;
m:longint;
zn:string;
begin
While str<>' ' do
begin
i:=i+1;
if str[i]=' ' then
begin
zn:=copy(str,0,i);
str:=copy(str,i,length(str)-i+1);
i:=0;
m:=0;
if zn='+' then obrabotka(1) else
if zn='-' then obrabotka(2) else
if zn='*' then obrabotka(3) else
if zn='/' then obrabotka(4) else
begin
val(zn,m,code);
AddStek(m);
end;
end;
end;
P:=top;
Result:=P^.num1;
end;
end.
interface
Type
Ukaz=^ stek;
Stek = record
num1:longint;
next:Ukaz;
end;
Var
top,P:Ukaz;
procedure AddStek(znak:longint);
procedure DelStek;
procedure obrabotka(dey:integer);
procedure Stroka(str:string; result:longint);
implementation
{procedure AddStek(znak:longint);}
procedure AddStek;
begin
New(P);
P^.num1:=znak;
P^.Next:=top;
top:=P;
end;
procedure DelStek;
begin
P:=top;
top:=top^.Next;
Dispose(P);
end;
{procedure obrabotka(dey:integer);}
procedure obrabotka;
var
N:integer;
begin
if dey=1 then { + }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=N+P^.num1;
end
else
if dey=2 then { - }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=N-P^.num1;
end
else
if dey=3 then { * }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=N*P^.num1;
end
else
if dey=4 then { / }
begin
P:=top;
N:=P^.num1;
P:=P^.Next;
N:=round(N/P^.num1);
end;
DelStek;
{ DelStek;}
AddStek(N);
end;
{procedure Stroka(str:string; result:longint);}
procedure Stroka;
var
code,i:integer;
m:longint;
zn:string;
begin
While str<>' ' do
begin
i:=i+1;
if str[i]=' ' then
begin
zn:=copy(str,0,i);
str:=copy(str,i,length(str)-i+1);
i:=0;
m:=0;
if zn='+' then obrabotka(1) else
if zn='-' then obrabotka(2) else
if zn='*' then obrabotka(3) else
if zn='/' then obrabotka(4) else
begin
val(zn,m,code);
AddStek(m);
end;
end;
end;
P:=top;
Result:=P^.num1;
end;
end.