fork download
  1. program ideone;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. function MultiCharsCountAsString(AInput: array of AnsiChar): AnsiString;
  6. const
  7. COUNTED_CHAR_VALUE = AnsiChar(#32);
  8. var
  9. intCharToken, intCounterToken, intCharCount: Integer;
  10. begin
  11. Result := '';
  12. WriteLn(' "', AnsiString(AInput), '"'#10);
  13.  
  14. for intCharToken := Low(AInput) to High(AInput) do
  15. if AInput[intCharToken] <> COUNTED_CHAR_VALUE then
  16. begin
  17. intCharCount := 1;
  18.  
  19. for intCounterToken := intCharToken + 1 to High(AInput) do
  20. if AInput[intCharToken] = AInput[intCounterToken] then
  21. begin
  22. Inc(intCharCount);
  23. AInput[intCounterToken] := COUNTED_CHAR_VALUE;
  24. end;
  25.  
  26. if intCharCount > 1 then
  27. Result += AInput[intCharToken];
  28.  
  29. WriteLn(intCharToken:3, ': "', AnsiString(AInput), '" | ', Result);
  30. end;
  31. end;
  32.  
  33. const
  34. STRING_TO_TEST = AnsiString('aabbcdeffaacggghijjjkb');
  35. var
  36. strResult: AnsiString;
  37. begin
  38. strResult := MultiCharsCountAsString(STRING_TO_TEST);
  39. Write(#10, 'Result: "', strResult, '"');
  40. ReadLn;
  41. end.
  42.  
Success #stdin #stdout 0s 280KB
stdin
Standard input is empty
stdout
     "aabbcdeffaacggghijjjkb"

  0: "a bbcdeff  cggghijjjkb" | a
  2: "a b cdeff  cggghijjjk " | ab
  4: "a b cdeff   ggghijjjk " | abc
  5: "a b cdeff   ggghijjjk " | abc
  6: "a b cdeff   ggghijjjk " | abc
  7: "a b cdef    ggghijjjk " | abcf
 12: "a b cdef    g  hijjjk " | abcfg
 15: "a b cdef    g  hijjjk " | abcfg
 16: "a b cdef    g  hijjjk " | abcfg
 17: "a b cdef    g  hij  k " | abcfgj
 20: "a b cdef    g  hij  k " | abcfgj

Result: "abcfgj"