function CountSym(ch: char; s: string): byte;
begin
if Pos(ch, s) <> 0 then
CountSym := 1 + CountSym(ch, Copy(s, Pos(ch,s)+1, Length(s)))
end;
var
s:string;
count:byte;
begin
readln(s);
count:=CountSym('ab',s);
writeln('kol-vo , = ',count);
end.
Вариант 2
var
s:string;
count:integer;
begin
readln(s);
while pos('ab',s) > 0 do begin
inc(count);
delete(s,pos('ab',s),2);
end;
writeln(count);
end.