Pagini recente » Cod sursa (job #2138584) | Cod sursa (job #1090659) | Cod sursa (job #2642213) | Cod sursa (job #1832202) | Cod sursa (job #106865)
Cod sursa(job #106865)
var fi,fo:text;
sir:ansistring;
cuv:array[0..55000]of string;
solutie: string;
cont,ct,ct2,ct3:int64;
i:longint;
procedure heapsort(n:int64);
var i,j,k:longint;
aux:string;
begin
for i:=1 to n do
begin
j:=i;
while (j shr 1<>0) and (cuv[j shr 1]<cuv[j]) do
begin
aux:=cuv[j shr 1];
cuv[j shr 1]:=cuv[j];
cuv[j]:=aux;
j:=j shr 1;
end;
end;
i:=n;
while i>1 do
begin
aux:=cuv[1];
cuv[1]:=cuv[i];
cuv[i]:=aux;
dec(i);
j:=1;
while (j>0) do
begin
k:=j shl 1;
if (k>i) then break;
if (k+1<=i) and (cuv[k+1]>cuv[k]) then inc(k);
if cuv[j]>=cuv[k] then break;
aux:=cuv[j];
cuv[j]:=cuv[k];
cuv[k]:=aux;
j:=k;
end;
end;
end;
function find(x:int64; aux:string):boolean;
var st,dr,mij:int64;
begin
st:=1; dr:=x; find:=false;
while st<=dr do
begin
mij:=(st+dr) shr 1;
if (cuv[mij]=aux) then begin find:=true; exit; end
else
if cuv[mij]>aux then dr:=mij-1
else st:=mij+1;
end;
end;
begin
assign(fi,'abc2.in'); reset(fi);
assign(fo,'abc2.out'); rewrite(fo);
readln(fi,sir); ct:=0;
while not eof(fi) do
begin
inc(ct); readln(fi,cuv[ct]); end;
heapsort(ct);
ct2:=length(cuv[1]); ct3:=length(sir); cont:=0;
for i:=1 to ct3-ct2+1 do
begin
solutie:=copy(sir,1,ct2);
if find(ct,solutie) then inc(cont);
delete(sir,1,1); end;
writeln(fo,cont);
close(fi); close(fo);
end.