var s:string; n,i,j,k:longint;
a:array[0..100]of string; t1,t2:string;
procedure insert(x:string);
begin
inc(k); a[k]:=x;
end;
function pop:string;
begin
pop:=a[k];
dec(k);
end;
procedure init;
begin
readln(s); n:=length(s);
k:=0;
for i:=1 to 100 do a[i]:='';
for i:=1 to n do
begin
if not(s[i] in ['+','-','*','/']) then insert(s[i])
else
begin
t1:=pop; t2:=pop;
if(length(t1)=1)and(length(t2)=1) then insert(t2+s[i]+t1)
else if(length(t1)>1)and(length(t2)=1) then
insert(t2+s[i]+'('+t1+')')
else if(length(t1)=1)and(length(t2)>1) then
insert('('+t2+')'+s[i]+t1)
else if(length(t1)>1)and(length(t2)>1) then
insert('('+t2+')'+s[i]+'('+t1+')');
end;
end;
end;
procedure print;
begin
for i:=1 to k do write(a[i]);
end;
begin
init;
print;
end.
-----------
后缀表达式转换成中缀。。。我没设优先级。。。成功的把一道堆栈的题改成了二分去括号………………
a:array[0..100]of string; t1,t2:string;
procedure insert(x:string);
begin
inc(k); a[k]:=x;
end;
function pop:string;
begin
pop:=a[k];
dec(k);
end;
procedure init;
begin
readln(s); n:=length(s);
k:=0;
for i:=1 to 100 do a[i]:='';
for i:=1 to n do
begin
if not(s[i] in ['+','-','*','/']) then insert(s[i])
else
begin
t1:=pop; t2:=pop;
if(length(t1)=1)and(length(t2)=1) then insert(t2+s[i]+t1)
else if(length(t1)>1)and(length(t2)=1) then
insert(t2+s[i]+'('+t1+')')
else if(length(t1)=1)and(length(t2)>1) then
insert('('+t2+')'+s[i]+t1)
else if(length(t1)>1)and(length(t2)>1) then
insert('('+t2+')'+s[i]+'('+t1+')');
end;
end;
end;
procedure print;
begin
for i:=1 to k do write(a[i]);
end;
begin
init;
print;
end.
-----------
后缀表达式转换成中缀。。。我没设优先级。。。成功的把一道堆栈的题改成了二分去括号………………

