Ver Mensaje Individual
  #10  
Antiguo 15-11-2010
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Rioja72.

Para sumar alguna idea te pongo un código que hasta donde probé funciona.
Dados los datos, genera todas las combinaciones posibles, aunque no necesariamente en el órden que mostras en tu ejemplo.
La cantidad de elementos de las listas, así como el número de elementos por grupos se ajustan con tres SpinEdits.
Te quedaría probarlo más a fondo y ver si te puede servir. (o al menos espero que te aporte alguna idea)

Código Delphi [-]
type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SpinEditLstA: TSpinEdit; 
    SpinEditLstB: TSpinEdit; 
    SpinEditNGrp: TSpinEdit;
    StringGrid1: TStringGrid;
    btMostrar: TButton;
    procedure FormShow(Sender: TObject);
    procedure btMostrarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);    
  private
    MAXLSTA, MAXLSTB: Integer;
    FGrupoA, FGrupoB, FParejas: Tstrings;
    procedure Inicializar;
    procedure Mostrar(NElem: Integer);
  public
  end;

var
 Form1: TForm1;

implementation {$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  // Crear Listas;
  FGrupoA:= TStringList.Create;
  FGrupoB:= TStringList.Create;
  FParejas:= TStringList.Create;
end;

procedure TForm1.Inicializar;
var
  c,f,x: Integer;
begin
  // Vaciar listas
  FGrupoA.Clear;
  FGrupoB.Clear;
  FParejas.Clear;
  // Ajustar base 0
  MAXLSTA:= SpinEditLstA.Value-1;
  MAXLSTB:= SpinEditLstB.Value-1;
  // Inicializar valores
  for x:= 0 to MAXLSTA do
    FGrupoA.Add('A'+IntToStr(x+1));
  for x:= 0 to MAXLSTB do
    FGrupoB.Add('B'+IntToStr(x+1));
  // Hacer los pares
  for f:= 0 to MAXLSTA do
  begin
    x:= f;
    for c:= 0 to MAXLSTB  do
    begin
      if x < MAXLSTA then
        Inc(x)
      else
        x:= 0;
      FParejas.Add(FGrupoA[x]+' '+FGrupoB[c]);
    end;
  end;
end;

procedure TForm1.Mostrar(NElem: Integer);
var
  i,j,NGrp,ix: Integer;
begin
  // Inicializar valores
  Inicializar; 
  // Limpiar StringGrid
  for i:= 0 to 10 do
    for j:= 0 to 10 do
      StringGrid1.Cells[i,j]:= '';
  // Obtener Nro de grupos
  NGrp:= (FParejas.Count) div NElem;
  for ix:= 1 to NGrp do
    StringGrid1.Cells[ix,0]:= 'Grupo '+IntToStr(ix);
  // Distribuir parejas
  ix:= 0;
  for i:= 1 to NGrp do
   for j:= 1 to NElem do
   begin
     StringGrid1.Cells[i,j]:= FParejas[ix];
     Inc(ix);
   end;
   // Si sobran elementos, agregar parejas faltantes
  ix:= FParejas.Count-(NGrp*NElem);
  if ix > 0 then
  begin
    StringGrid1.Cells[NGrp+1,0]:= 'Grupo ' + IntToStr(NGrp+1);
    for i:= 0 to ix - 1 do
      StringGrid1.Cells[NGrp+1, i+1]:= FParejas[FParejas.Count-ix+i];
  end;
end;

procedure TForm1.btMostrarClick(Sender: TObject);
begin
  Mostrar(SpinEditNGrp.Value);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  // Liberar TStrings
  FGrupoA.Free;
  FGrupoB.Free;
  FParejas.Free;
end;
end.

Saludos.

Última edición por ecfisa fecha: 15-11-2010 a las 08:45:16.
Responder Con Cita