Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Hau_to;
- uses crt;
- Type
- mang=array[1..1000]of string[10];
- mang1=array[1..1000] of real;
- var bthuc:mang;
- s:mang1;
- i,n,kt,T:integer;
- x,y,z,w:real;
- procedure Push(var S:mang1;var T:integer; X:real);
- begin
- if (T>=n) then
- writeln('Tran STACK.')
- else
- begin
- inc(t);
- s[T]:=x;
- end;
- textcolor(red);
- writeln('Da day so ',x:2:2,' vao STACK.');
- textcolor(white);
- End;
- Function Pop(S:mang1;var T:integer):real;
- begin
- if T<=0 then
- writeln('STACK het.')
- else
- begin
- Pop:=s[t];
- textcolor(blue);
- writeln(' Lay ',s[t]:2:2,' ra khoi STACK.');
- textcolor(white);
- dec(t);
- end;
- End;
- Procedure Nhap;
- begin
- i:=0;
- textcolor(green);
- writeln('Nhap tung phan tu cua bieu thuc.');
- writeln('Nhap # de ket thuc bieu thuc.');
- textcolor(white);
- writeln;
- repeat
- inc(i);
- write('Nhap phan tu: ');
- readln(bthuc[i]);
- until bthuc[i]='#';
- n:=i;
- end;
- Begin
- clrscr;
- Nhap;
- for i:=1 to n-1 do
- write(bthuc[i],' ');
- i:=1;
- writeln;
- t:=0;
- Repeat
- val(bthuc[i],x,kt);
- if kt=0 then
- push(s,t,x)
- else
- begin
- y:=Pop(S,t);
- z:=Pop(S,t);
- textcolor(yellow);
- if bthuc[i]='+' then
- begin
- writeln('Thuc hien phep toan ',z:2:2,bthuc[i],y:2:2,'=',z+y:2:2);
- w:=y+z;
- end;
- if bthuc[i]='-' then
- begin
- writeln('Thuc hien phep toan ',z:2:2,bthuc[i],y:2:2,'=',z-y:2:2);
- w:=z-y;
- end;
- if bthuc[i]='*' then
- begin
- writeln('Thuc hien phep toan ',z:2:2,bthuc[i],y:2:2,'=',z*y:2:2);
- w:=z*y;
- end;
- if bthuc[i]='/' then
- begin
- writeln('Thuc hien phep toan ',z:2:2,bthuc[i],y:2:2,'=',z/y:2:2);
- w:=z/y;
- end;
- textcolor(white);
- delay(1250);
- Push(s,t,w);
- end;
- inc(i);
- until bthuc[i]='#';
- textcolor(green);
- writeln;
- write('Dinh gia cua bieu thuc = ',w:4:2);
- readln
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement