1 solutions

  • 0
    @ 2025-11-5 17:18:14

    Pascal :

    program qi26868;
    type
     point=^treetype;
     treetype=record
      data:char;
      son1,son2:point;
     end;
    var
     head:point;
    
    
    procedure du(var head:point);
    var
     p:point;
     ch:char;
     k,top:longint;
     s:array[1..100]of point;
    begin
     read(ch);
     k:=0;  top:=0;
     while ch<>'#' do
      begin
       case ch of
        'A'..'Z':
          begin
           new(p); p^.data:=ch; p^.son1:=nil; p^.son2:=nil;
           if top<>0 then
            begin
             if k=1 then s[top]^.son1:=p;
             if k=2 then s[top]^.son2:=p;
            end;
          end;
         '(':begin top:=top+1; s[top]:=p; k:=1; end;
         ')':top:=top-1;
         ',':k:=2;
      end;
      read(ch);
     end;
     head:=s[1];
    end;
    
    
    procedure xianxu(head:point);
    begin
     if head<>nil then
      begin
       write(head^.data);
       xianxu(head^.son1);
       xianxu(head^.son2)
      end;
    end;
    
    
    begin
     du(head); xianxu(head);
    end.
    
    • 1

    Information

    ID
    18272
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By