Pagini recente » Cod sursa (job #563394) | Cod sursa (job #1972788) | Cod sursa (job #1249357) | Cod sursa (job #890109) | Cod sursa (job #138126)
Cod sursa(job #138126)
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.