function GetRepStrMax(Const S : String) : integer;
var
  i , n : integer;
  P : PChar;
  LC : Char;
begin
  Result := 0;
  P := Pointer(S);
  if S<>'' then begin
    LC := P^;
    n := 0;
    for i:=0 to Length(S)-1 do begin
      if P[i]=LC then inc(n)
      else begin
        if n>Result then Result := n;
        LC := P[i];
        n := 1;
      end;
    end;
  end;
end;

解决方案 »

  1.   

    function GetRepStrMax(Const S : String) : integer;
    var
      i , n : integer;
      P : PChar;
      LC : Char;
    begin
      Result := 0;
      P := Pointer(S);
      if S<>'' then begin
        LC := P^;
        n := 0;
        for i:=0 to Length(S)-1 do begin
          if P[i]=LC then inc(n)
          else begin
            if n>Result then Result := n;
            LC := P[i];
            n := 1;
          end;
        end;
        if Result=0 then Result := n;  //加这一句即可
      end;
    end;