function ZsDispose(mCount: Integer): string;
  function f(mLength: Integer): string;
  var
    I, L: Integer;
    S1, S2: string;
  begin
    if mLength = 1 then
      Result := '01'
    else if mLength > 1 then begin
      Result := f(Pred(mLength));
      L := Length(Result);
      S1 := '';
      for I := 1 to L do begin
        if Pred(I) mod Pred(mLength) = 0 then
          AppendStr(S1, '0');
        AppendStr(S1, Result[I]);
      end;      S2 := '';
      for I := 1 to L do begin
        if Pred(I) mod Pred(mLength) = 0 then
          AppendStr(S2, '1');
        AppendStr(S2, Result[I]);
      end;
      Result := S1 + S2;
    end else Result := '';
  end;
var
  I: Integer;
  S: string;
begin
  S := f(mCount);
  for I := 1 to Length(S) do begin
    if Pred(I) mod mCount = 0 then
      AppendStr(Result, ',');
    AppendStr(Result, S[I]);
  end;
  Delete(Result, 1, 1);
end;

解决方案 »

  1.   

    procedure TForm1.writebin( n : integer );
    var
      y,i,t,k,count:integer;
      s : string;
    begin
      for t:=1 to n do
      begin
        setlength(s,t+1);
        y:=(1 shl t);
        for i:= 1 to y do
        begin
          count := t;
          k:=i-1;
          while count>0 do
          begin
            s[count]:=char((k mod 2)+48);
            count:=count-1;
            k:=(k div 2);
          end;
          listbox1.items.add(s);
        end;
      end;
    end;