Показать сообщение отдельно
  #13  
Старый 18.12.2011, 23:31
anderbeli anderbeli вне форума
Прохожий
 
Регистрация: 18.12.2011
Сообщения: 12
Репутация: 10
По умолчанию

нашел , но как то не так как в исходники выводит
Код:
procedure MoveOneElementWithShift( Row, Col : integer; var M : TDynArray);
var
  i, j,
    MaxJ, MasPosition, NextI, NextJ : integer;
begin
  for i := Row to Length(M) - 1 do begin
     if (i = Row)
        then j := Col
        else j := 0;
     if (i = (Length(M)-1))
        then MaxJ := Length(M[i]) - 2
        else MaxJ := Length(M[i]) - 1;
     while j <= MaxJ do begin
        MasPosition := i*Length(M[i]) + j;
        NextI := (MasPosition + 1) div Length(M[i]);
        NextJ := (MasPosition + 1) mod Length(M[i]);
        M[i, j] := M[NextI, NextJ];
        inc(j);
     end;

     {åńėč ļīńėåäķ˙˙ ńņšīźą, óģåķüųčģ šąēģåš ļīńėåäķåé ńņšī÷źč ķą 1}
     if (i = (Length(M)-1))
       then if Length(M[i])>0 then SetLength(M[i], Length(M[i]) - 1);
  end;
  if Length(M[Length(M)-1]) = 0 then
              SetLength(M, Length(M) - 1)

end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: integer;
begin
  Randomize;

  StringGrid1.FixedRows := 0;
  StringGrid1.FixedCols := 0;

  SetLength(Mas, StrToInt(Edit1.Text), strToInt(Edit2.Text));
  StringGrid1.RowCount := StrToInt(Edit1. Text);
  StringGrid1.ColCount := strToInt(Edit2. Text);
  for i := 0 to Length(mas) - 1 do
    for j := 0 to Length(mas[i]) - 1 do
    begin
      if chbLinearNumbers.Checked then
         Mas[i, j] := i*Length(mas[i])+j+1
      else
         Mas[i, j] := StrToInt(Edit3.text) + Random(StrToInt(Edit4.Text) - StrToInt(Edit3.text) + 1);
         
      StringGrid1.Cells[j, i] := IntToStr(Mas[i, j]);
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i, j: integer;
begin
  if (StringGrid1.Row+1>Length(mas)) then begin
    Application.MessageBox('ß÷åéźą ķå óźąēūāąåņ ķą żėåģåķņ ģąńńčāą', 'Īųčįźą', MB_ICONINFORMATION or MB_OK);
    Exit;
  end;
  if (StringGrid1.Col+1>Length(mas[StringGrid1.Row])) then begin
    Application.MessageBox('ß÷åéźą ķå óźąēūāąåņ ķą żėåģåķņ ģąńńčāą', 'Īųčįźą', MB_ICONINFORMATION or MB_OK);
    Exit;
  end;

  MoveOneElementWithShift( StringGrid1.Row, StringGrid1.Col, Mas );

  for i := 0 to StringGrid1.RowCount-1  do
    for j := 0 to StringGrid1.ColCount-1 do
    begin
      StringGrid1.Cells[j, i] := '';
    end;


  for i := 0 to Length(mas) - 1 do
    for j := 0 to Length(mas[i]) - 1 do
    begin
      StringGrid1.Cells[j, i] := IntToStr(Mas[i, j]);
    end;

end;

end.
Ответить с цитированием