Cod sursa(job #138126)

Utilizator tamas_iuliaTamas Iulia tamas_iulia Data 17 februarie 2008 21:45:55
Problema Restante Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.45 kb
var a : array[0..36000] of string[16];
    i,n,tot : longint;
    f,g : text;
    cuv : string;
    ok : boolean;
procedure quick(l,r : longint);
var i,j : longint;
    x,y : string;
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 i<=j then
     begin
          y:=a[i];a[i]:=a[j];a[j]:=y;
          inc(i); dec(j);
     end;
until i>j;
if l<j then quick(l,j);
if i<r then quick(i,r);
end;
procedure quick_cuv(l,r,poz : longint; var cuv : string[17]);
var i,j : longint;
    x,y : char;
begin
     i:=l; j:=r; x:=cuv[(l+r)div 2];
repeat
     while cuv[i]<x do inc(i);
     while x<cuv[j] do dec(j);
     if i<=j then
     begin
          y:=cuv[i];cuv[i]:=cuv[j];cuv[j]:=y;
          inc(i); dec(j);
     end;
until i>j;
if l<j then quick_cuv(l,j,poz,cuv);
if i<r then quick_cuv(i,r,poz,cuv);
end;
begin
assign(f,'restante.in'); reset(f);
assign(g,'restante.out'); rewrite(g);
readln(f,n);
for i:=1 to n do readln(f,a[i]);
for i:=1 to n do quick_cuv(1,length(a[i]),i,a[i]);
quick(1,n);
{for i:=2 to n do
  if a[i]=a[i-1] then a[i-1]:='-1'
      else if a[i-2]='-1' then a[i-1]:='-1';
for i:=1 to n do if a[i]<>'-1' then inc(tot);}
i:=1;
repeat
ok:=false;
if a[i]=a[i+1] then
begin
     cuv:=a[i];
     while a[i]=cuv do inc(i);
end;
while (a[i]<>a[i+1]) and (i<=n) do
begin
     inc(tot);
     inc(i);
end;
until i>=n;
writeln(g,tot);
close(g);
end.