program dgdfgdfg;
uses crt;
type
ref=^z;
z=record
next:ref;
el:char;
end;
inout=(in1,out);
FIFO=array[in1..out] of ref;
var order,order1:FIFO;a,h:char;q:ref;n,k,t:integer;
begin
clrscr;
new(order[in1]);
order[out]:=order[in1];
order[in1]^.next:=nil;
new(order1[in1]);
order1[out]:=order1[in1];
order1[in1]^.next:=nil;
repeat
readln(a);
new(q);
q^.next:=nil;
q^.el:=a;
order[in1]^.next:=q;
order[in1]:=q;
n:=n+1;
until a='.';
while k<>n do
begin
q:=order[out]^.next; h:=q^.el;
if h in ['0'..'9']
then
begin
write(' ',q^.el);
order[out]^.next:=q^.next;
if q^.next=nil
then order[in1]:=order[out];
dispose(q);
t:=t+1;
end
else
begin
order[out]^.next:=q^.next;
order1[in1]^.next:=q;
order1[in1]:=q;
end;
k:=k+1;
end;
k:=0;
while k<>n-t do
begin
q:=order1[out]^.next;
write(' ',q^.el);
order1[out]^.next:=q^.next;;
dispose(q);
k:=k+1;
end;
readkey;
end.
Задача на очередь |