Cod sursa(job #343478)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 25 august 2009 23:04:11
Problema Restante Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.05 kb
var v:array[1..36001]of string[16];
s:string[16];
n,c,i:word;
ok:boolean;

procedure sort1(a,b:byte);
var i,j:byte;
mij,aux:char;
begin
i:=a; j:=b;
mij:=s[(a+b)div 2];
repeat
while s[i]<mij do inc(i);
while s[j]>mij do dec(j);
if i<=j then begin
	aux:=s[i]; s[i]:=s[j]; s[j]:=aux;
	inc(i); dec(j);
	end;
until i>j;
if i<b then sort1(i,b);
if a<j then sort1(a,j);
end;

procedure sort2(a,b:word);
var i,j:word;
mij,aux:string[16];
begin
i:=a; j:=b;
mij:=v[(a+b)div 2];
repeat
while v[i]<mij do inc(i);
while v[j]>mij do dec(j);
if i<=j then begin
	aux:=v[i]; v[i]:=v[j]; v[j]:=aux;
	inc(i); dec(j);
	end;
until i>j;
if i<b then sort2(i,b);
if a<j then sort2(a,j);
end;


begin
assign(input,'restante.in');reset(input);
assign(output,'restante.out');rewrite(output);
readln(n);
for i:=1 to n do begin
	readln(s);
	sort1(1,length(s));
	v[i]:=s;
end;

sort2(1,n);

ok:=true; c:=0;
for i:=1 to n-1 do begin
	if (v[i]<>v[i+1])and(ok) then inc(c);
	ok:=v[i]<>v[i+1];
end;
if ok then inc(c);
writeln(c);
close(output);
end.