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

Discussion of Problem 1067. Disk Tree

I check my program for all test. Answers is equal! But I got WA! What Wrong??
Posted by Algorithmus_UA(algorithmus@univ.kiev.ua) 27 Aug 2002 15:29
var a:array[0..500]of string[85];
    N,i,j,k,num,p:integer;
procedure conv(i,j:integer;var num,p:integer);
var k:integer;
begin
{  if a[i]=a[j] then
  begin
    p:=length(a[i])+1;
    num:=0;
  end;}
  num:=0;p:=1;
  k:=0;
  for k:=1 to length(a[i]) do
  begin
    if a[i,k]<>a[j,k] then break
    else if a[i,k]=' ' then
    begin
      inc(num);
      p:=k+1;
    end;
  end;
  if (a[i,k]=a[j,k])and(k<>0)and((length(a[j])=length(a[i]))or(a
[j,k+1] = ' ')) then
  begin
      inc(num);
      p:=k+2;
  end;
end;

procedure sort(l,r: longint);
var i,j: longint;
    x,y: string[85];
begin
   i:=l;j:=r;x:=a[(l+r) div 2];
   repeat
     while a[i]<x do inc(i);
     while x<a[j] do dec(j);
     if not(i>j) then
       begin
          y:=a[i];
          a[i]:=a[j];
          a[j]:=y;
          inc(i);
          j:=j-1;
       end;
   until i>j;
   if l<j then sort(l,j);
   if i<r then sort(i,r);
end;

begin
{ assign(input,'disktree.in');
 reset(input);
 assign(output,'disktree.out');
 rewrite(output);}
 readln(n);
 for i:=1 to N do
 begin
   readln(a[i]);
   for j:=1 to length(a[i]) do if a[i,j] = '\' then a[i,j]:=' ';
 end;
 sort(1,N);
 for i:=1 to N do
 begin
   if a[i-1]=a[i] then continue;
   conv(i-1,i,num,p);
   for k:=1 to num do write(' ');
   for j:=p to length(a[i]) do
   begin
     if a[i,j]=' ' then
     begin
       inc(num);
       writeln;
       for k:=1 to num do write(' ');
     end
     else write(a[i,j]);
   end;
   writeln;
 end;
{ close(output);}
end.