Cod sursa(job #582314)

Utilizator originalalexmarin alexandru originalalex Data 15 aprilie 2011 10:54:32
Problema Restante Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.24 kb
program restante;
type cuvant=array[0..26]of byte;
     vector=array[1..36000]of cuvant;
var v:vector;
    nou:array[1..36000]of boolean;
    gol,cuv:cuvant;
    i,k,j,q,n,nr,p,l:word;
    f1,f2:text;
    s:string;
    egal,orig:boolean;
//v[1][3]=nr ap 'c' in primul cuv

begin
for i:=1 to 26 do
  gol[i]:=0;
nr:=0;
k:=0;
assign(f1,'restante.in');
reset(f1);
readln(f1,n);
for i:=1 to n do
  begin
  readln(f1,s);
  cuv:=gol;
  for j:=1 to length(s) do
    begin
    p:=ord(s[j])-ord('a')+1;
    cuv[p]:=cuv[p]+1;
    cuv[0]:=cuv[0]+1;
    end;
 orig:=true;
 j:=1;
 while orig and (j<=k) do
   begin
   if cuv[0]<>v[j][0] then
     egal:=false
   else
     begin
     egal:=true;
     q:=1;
     l:=0;
     while egal and (q<=26)and(l<cuv[0])do
       begin
       if cuv[q]<>v[j][q] then
         egal:=false;
       l:=l+cuv[q];
       q:=q+1
       end;
     if egal then
       begin
       orig:=false;
       if nou[j] then
         nr:=nr-1;
       nou[j]:=false;
       end;
     end;
   j:=j+1;
   end;
  if orig then
    begin
    k:=k+1;
    v[k]:=cuv;
    nou[k]:=true;
    nr:=nr+1;
    end;
  end;
close(f1);
assign(f2,'restante.out');
rewrite(f2);
writeln(f2,nr);
close(f2);
end.