ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

What is specaill? some question?
Posted by Locomotive 10 Feb 2003 19:17
what is anwer of
2
a\b
b
~~~~~
and also
2
a
A
~~~~~~
What is specail which made me get WA :(((
Type
  pnode               =^node;
  node                =record
     name             :string;
     rs               :pnode;
     lmc              :pnode;
   end;
  byte=integer;
Var
  t                   :char;
  n,i                 :integer;
  d                   :string;
  root,p,k,b4         :pnode;

Procedure DFS(x:pnode;l:byte);
Var
  y                   :pnode;
  i                   :byte;
begin
  y:=x^.lmc;
  while y<>nil do
  begin
    for i:=1 to l do
      write(' ');
    writeln(Y^.name);
    dfs(y,l+1);
    if y^.rs=nil then
      exit
    else
      y:=y^.rs;
  end;
end;

begin
  readln(n);
  new(root);
  for i:=1 to n do
  begin
    p:=root;
    repeat
      b4:=p;
      d:=''; read(t); if ord(t)<33 then continue;
      repeat d:=d+t; read(t); until (ord(t)=92) or (ord(t)<32) or eof
or eoln;
{-------------------ADD-------------------}
      if p^.lmc=nil then
      begin
        new(k);
        k^.rs:=nil;
        k^.lmc:=nil;
        k^.name:=d;
        p^.lmc:=k;
        p:=k;
      end
      else
      begin {P (Cuurrnet) HAS Child}
        p:=p^.lmc;
        if p^.name>=d then
          if p^.name>d then
          begin
            new(k);
            k^.rs:=p;
            k^.lmc:=nil;
            k^.name:=d;
            b4^.lmc:=k;
            p:=k;
          end
          else
        else
        begin {p-->the child of b4 } {his first child<name}
          if p^.rs<>nil then
            while p^.rs^.name<d do
            begin
              p:=p^.rs;
              if p^.rs=nil then break;
            end;
          if (p^.rs = nil) then
          begin
            new(k);
            k^.name:=d;
            k^.lmc:=nil;
            k^.rs:=nil;
            p^.rs:=k;
            p:=k;
          end
          else
            if (p^.rs^.name=d) then
              p:=p^.rs
            else
            begin
              new(k);
              k^.name:=d;
              k^.rs:=p^.rs;
              k^.lmc:=nil;
              p^.rs:=k;
              p:=k;
            end;
        end;
      end;
    until ord(t)<32;
    readln;
  end;
  dfs(root,0);
end.
(+)
Posted by Miguel Angel 10 Feb 2003 21:53
> what is anwer of
> 2
> a\b
> b
> ~~~~~

a
 b
b

> and also
> 2
> a
> A

A
a

> ~~~~~~

I think this problem is easier if you think it as a sort problem
instead of similutating.

> What is specail which made me get WA :(((
> Type
>   pnode               =^node;
>   node                =record
>      name             :string;
>      rs               :pnode;
>      lmc              :pnode;
>    end;
>   byte=integer;
> Var
>   t                   :char;
>   n,i                 :integer;
>   d                   :string;
>   root,p,k,b4         :pnode;
>
> Procedure DFS(x:pnode;l:byte);
> Var
>   y                   :pnode;
>   i                   :byte;
> begin
>   y:=x^.lmc;
>   while y<>nil do
>   begin
>     for i:=1 to l do
>       write(' ');
>     writeln(Y^.name);
>     dfs(y,l+1);
>     if y^.rs=nil then
>       exit
>     else
>       y:=y^.rs;
>   end;
> end;
>
> begin
>   readln(n);
>   new(root);
>   for i:=1 to n do
>   begin
>     p:=root;
>     repeat
>       b4:=p;
>       d:=''; read(t); if ord(t)<33 then continue;
>       repeat d:=d+t; read(t); until (ord(t)=92) or (ord(t)<32) or
eof
> or eoln;
> {-------------------ADD-------------------}
>       if p^.lmc=nil then
>       begin
>         new(k);
>         k^.rs:=nil;
>         k^.lmc:=nil;
>         k^.name:=d;
>         p^.lmc:=k;
>         p:=k;
>       end
>       else
>       begin {P (Cuurrnet) HAS Child}
>         p:=p^.lmc;
>         if p^.name>=d then
>           if p^.name>d then
>           begin
>             new(k);
>             k^.rs:=p;
>             k^.lmc:=nil;
>             k^.name:=d;
>             b4^.lmc:=k;
>             p:=k;
>           end
>           else
>         else
>         begin {p-->the child of b4 } {his first child<name}
>           if p^.rs<>nil then
>             while p^.rs^.name<d do
>             begin
>               p:=p^.rs;
>               if p^.rs=nil then break;
>             end;
>           if (p^.rs = nil) then
>           begin
>             new(k);
>             k^.name:=d;
>             k^.lmc:=nil;
>             k^.rs:=nil;
>             p^.rs:=k;
>             p:=k;
>           end
>           else
>             if (p^.rs^.name=d) then
>               p:=p^.rs
>             else
>             begin
>               new(k);
>               k^.name:=d;
>               k^.rs:=p^.rs;
>               k^.lmc:=nil;
>               p^.rs:=k;
>               p:=k;
>             end;
>         end;
>       end;
>     until ord(t)<32;
>     readln;
>   end;
>   dfs(root,0);
> end.