const delimiter = [#32, ',', '.', '!', ':']; type wrd_info = record start, len: byte; end; function get_words(s: string; var words: array of wrd_info; var diff: integer): integer; var count: integer; i, j, curr_len: byte; found: boolean; begin count := -1; i := 1; diff := 0; while i <= length(s) do begin while (s[i] in delimiter) and (i <= length(s)) do inc(i); curr_len := 0; while not (s[i] in delimiter) and (i <= length(s)) do begin inc(i); inc(curr_len); end; if curr_len > 0 then begin found := false; for j := 0 to count do if copy(s, words[j].start, words[j].len) = copy(s, i - curr_len, curr_len) then found := true; if not found then inc(diff); inc(count); with words[count] do begin start := i - curr_len; len := curr_len end; end; end; get_words := count + 1; end; const max_word = 255; var words: array[1 .. max_word] of wrd_info; i, n, diff: integer; const s: string = 'ogog, thats,,, all :: foolks !!! bye foolks, bye...'; var T: string; j, count: integer; begin n := get_words(s, words, diff); writeln('different words count: ', diff); for i := n downto 1 do begin T := copy(s, words[i].start, words[i].len); count := 0; for j := 1 to length(T) do inc(count, byte(T[j] = 'o')); if count = 2 then delete(s, words[i].start, words[i].len); end; writeln('s = ', s); end.