Показать сообщение отдельно
  #8  
Старый 04.04.2008, 23:48
Farmazon Farmazon вне форума
Прохожий
 
Регистрация: 04.04.2008
Сообщения: 14
Репутация: 10
По умолчанию

Вот, тут создаётся матрица случайным образом заполняется, меняет первый и последний столбец...это в обработке щелчка на Бутон2. я полный код выложу, на форму прикрепиш чё попросит дельфи, глянеш нормально, подредактируеш под своё задание. Тут фишка в том чт что переносимый столбец матрицы в одномерный массив пишется, получается что первый и последний столбцы каждый в свой одномерн массив пишутся, а потом дописываются наоборот в матрицу.
Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a : array [1..50, 1..50] of integer;
  b : array [1..50] of integer;
  c : array [1..50] of integer;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var n,m,i,j:integer;f:TextFile;
begin
Randomize;
AssignFile (f,'f1.txt');
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
For i:=0 to n-1 do
    For j:=0 to m-1 do a[i,j]:=Random(100)-50;
StringGrid1.RowCount:=n+1;
StringGrid1.ColCount:=m+1;
With StringGrid1 do
    Begin
        i:=0;
        For j:=1 to RowCount do
            Cells[i,j]:=IntToStr(j);
        j:=0;
        For i:=1 to ColCount do
            Cells[i,j]:=IntToStr(i);
    End;
Rewrite(f);
With StringGrid1 do
    For i:=1 to n do
        For j:=1 to m do
            Begin
                Cells[j,i]:=IntToStr(a[i-1,j-1]);
                WriteLn(f,a[i-1,j-1]);
            End;
CloseFile(f);
end;

procedure TForm1.Button2Click(Sender: TObject);
var n,m,i,j:integer; f:TextFile;
begin
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
AssignFile (f,'f2.txt');
j:=0;
For i:=0 to m-1 do
    Begin
        b[i]:=a[i,j];
    End;
j:=m-1;
For i:=0 to m-1 do c[i]:=a[i,j];
For i:=0 to m-1 do a[i,j]:=b[i];
j:=0;
For i:=0 to m-1 do a[i,j]:=c[i];
StringGrid2.RowCount:=n+1;
StringGrid2.ColCount:=m+1;
With StringGrid2 do
    Begin
        i:=0;
        For j:=1 to RowCount do
            Cells[i,j]:=IntToStr(j);
        j:=0;
        For i:=1 to ColCount do
            Cells[i,j]:=IntToStr(i);
    End;
Rewrite(f);
With StringGrid2 do
    For i:=1 to n do
        For j:=1 to m do
            Begin
                Cells[j,i]:=IntToStr(a[i-1,j-1]);
                WriteLn(f,a[i-1,j-1]);
            End;
CloseFile(f);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;

end.