Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit F_LAB_5_2;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, MyUtils,
- ClipBrd, Vcl.Menus, AboutDev;
- type
- T2DArray = array of array of Integer;
- TForm1 = class(TForm)
- sgA: TStringGrid;
- edtN: TEdit;
- btnBuild: TButton;
- btnClear: TButton;
- MainMenu1: TMainMenu;
- N4: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- procedure edtNKeyPress(Sender: TObject; var Key: Char);
- procedure btnBuildClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure btnClearClick(Sender: TObject);
- procedure N5Click(Sender: TObject);
- procedure N6Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- const
- MAX_GRID_RANK = 12;
- implementation
- {$R *.dfm}
- procedure TForm1.btnBuildClick(Sender: TObject);
- var
- N, i, j, p, Temp: Integer;
- A: T2DArray;
- S: String;
- begin
- try
- N := StrToInt(edtN.Text);
- if not(N mod 4 = 0) then
- MessageBox(0, PChar('Квадрат должен быть четного порядка!'),
- 'Warning!', MB_OK + MB_ICONERROR)
- else
- begin
- SetLength(A, N, N);
- sgA.ColCount := N;
- sgA.RowCount := N;
- CorrectStringGridView(sgA, MAX_GRID_RANK, MAX_GRID_RANK);
- for i := 0 to N - 1 do
- for j := 0 to N - 1 do
- begin
- A[i, j] := i * N + j + 1;
- end;
- for i := 0 to N div 4 - 1 do
- for j := 0 to N div 4 - 1 do
- begin
- for p := 0 to 1 do
- begin
- Temp := A[i * 4 + p, j * 4 + p];
- A[i * 4 + p, j * 4 + p] :=
- A[N - (i * 4 + p) - 1, N - (j * 4 + p) - 1];
- A[N - (i * 4 + p) - 1, N - (j * 4 + p) - 1] := Temp;
- Temp := A[i * 4 + p, j * 4 + 3 - p];
- A[i * 4 + p, j * 4 + 3 - p] :=
- A[N - (i * 4 + p) - 1, N - (j * 4 + 3 - p) - 1];
- A[N - (i * 4 + p) - 1, N - (j * 4 + 3 - p) - 1] := Temp;
- end;
- end;
- for i := 0 to N - 1 do
- begin
- for j := 0 to N - 1 do
- begin
- sgA.Cells[j, i] := IntToStr(A[i, j]);
- S := S + sgA.Cells[j, i] + #9;
- end;
- S := S + #13;
- end;
- Clipboard.AsText := S;
- end;
- except
- MessageBox(0, PChar('Некорректные данные в поле ввода.'), 'Warning!',
- MB_OK + MB_ICONERROR);
- btnClear.Click;
- end;
- end;
- procedure TForm1.btnClearClick(Sender: TObject);
- begin
- edtN.Text := '';
- sgA.ColCount := 0;
- sgA.RowCount := 0;
- sgA.Cells[0, 0] := '';
- end;
- procedure TForm1.edtNKeyPress(Sender: TObject; var Key: Char);
- begin
- CorrectNaturalInput(edtN, Key);
- sgA.ColCount := 0;
- sgA.RowCount := 0;
- sgA.Cells[0, 0] := '';
- CorrectStringGridView(sgA, MAX_GRID_RANK, MAX_GRID_RANK);
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- CorrectStringGridView(sgA, MAX_GRID_RANK, MAX_GRID_RANK);
- end;
- procedure TForm1.N5Click(Sender: TObject);
- begin
- MessageBox(0, PChar('Задача:' + #13#13 +
- 'Построение магического квадрата четно-четного порядка (4×4, 8×8, 12×12 и т.д.) методом Рауз-Болла.'
- + #10#13 + 'Ответ доролнительно копируется в буфер обмена'),
- PChar('О программе'), MB_OK);
- end;
- procedure TForm1.N6Click(Sender: TObject);
- begin
- AboutMe.Show;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement