Cod sursa(job #125184)

Utilizator CezarMocanCezar Mocan CezarMocan Data 20 ianuarie 2008 11:55:49
Problema Restante Scor 100
Compilator fpc Status done
Runda preONI 2008, Runda 3, Clasa a 9-a Marime 1.42 kb
const m=666013;

var v:array[1..36100] of string[20];
    n,i,j,h,p,nr,p1,p2:longint;
    c:char;
    x:array['a'..'z'] of integer;
    aux:string[20];

procedure qsort(ls,ld:longint);
var i,j:longint;
    aux:string[20];
begin
  i:=ls;j:=ld;
  while true do begin
    while (v[i]<=v[j])and(i<>j) do inc(i);
    if i=j then break;
    aux:=v[i];v[i]:=v[j];v[j]:=aux;dec(j);
    while (v[i]<=v[j])and(i<>j) do dec(j);
    if i=j then break;
    aux:=v[i];v[i]:=v[j];v[j]:=aux;inc(i);
  end;
  if j-1>ls then qsort(ls,j-1);
  if j+1<ld then qsort(j+1,ld);
end;


begin
assign(input,'restante.in');reset(input);
assign(output,'restante.out');rewrite(output);
readln(n);
for i:=1 to n do
        begin
        readln(v[i]);
        p:=length(v[i]);
        fillchar(x,sizeof(x),0);
        for j:=1 to p do
                inc(x[v[i,j]]);
        v[i]:='';
        for c:='a' to 'z' do
                for j:=1 to x[c] do
                        v[i]:=v[i]+c;
        end;
randomize;
for i:=1 to 5000 do
        begin
        p1:=random(n)+1;
        p2:=random(n)+1;
        aux:=v[p1];
        v[p1]:=v[p2];
        v[p2]:=aux;
        end;
qsort(1,n);
i:=1;
while (i<=n) do
        begin
        j:=i;
        while (v[j]=v[i])and(j<=n) do
                inc(j);
        if (j-i=1) then
                inc(nr);
        i:=j;
        end;
writeln(nr);
close(input);close(output);
end.