Pagini recente » Cod sursa (job #105221) | Cod sursa (job #2852910) | Cod sursa (job #3159669) | Cod sursa (job #2535418) | Cod sursa (job #105240)
Cod sursa(job #105240)
type pelem=^elem;
elem=record
info:int64;
next:pelem;
end;
var last:pelem;
fi,fo:text;
cont,ct3,lung:int64;
i:longint;
cuvant:string;
type vectoras=array['a'..'c']of byte;
const baza3:vectoras=(0,1,2);
function b3aza10(Cuvant:string[30]):int64;
{conversie din baza 3 in baza 10}
var i:integer;
rez,p:int64;
begin
p:=1; rez:=0;
for i:=length(Cuvant) downto 1 do
begin
rez:=rez+baza3[Cuvant[i]]*p;
p:=p*3;
end;
b3aza10:=rez;
end;
procedure ins(var first:pelem; vl:int64);
var p:pelem;
begin
if first=nil then
begin
new(first);
first^.info:=vl;
first^.next:=nil;
last:=first;
end
else
begin
new(p);
p^.info:=vl;
p^.next:=nil;
last^.next:=p;
last:=p;
end;
end;
function cauta(first:pelem; vl:int64):boolean;
var p:pelem;
begin
p:=first;
while p<>nil do
begin
if p^.info=vl then begin cauta:=true; exit; end;
p:=p^.next;
end;
cauta:=false;
end;
procedure print(first:pelem);
var p:pelem;
begin
p:=first;
while p<>nil do
begin
writeln(fo,p^.info);
p:=p^.next;
end;
end;
var sir:ansistring;
cuv:string[30];
a:pelem;
begin
assign(fi,'abc2.in'); reset(fi);
assign(fo,'abc2.out'); rewrite(fo);
readln(fi,sir);
while not eof(fi) do
begin
readln(fi,cuv);
ins(a,b3aza10(cuv)); end;
ct3:=length(sir); lung:=length(cuv); cont:=0;
for i:=1 to ct3-3 do
begin
cuvant:=copy(sir,1,lung);
if cauta(a,b3aza10(cuvant)) then inc(cont);
delete(sir,1,1);
end;
writeln(fo,cont);
close(fi);
close(fo);
end.