19.11.2013, 21:43
|
#4 (permalink)
|
VIP user
Регистрация: 10.03.2011
Сообщений: 765
Сказал(а) спасибо: 10
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 3453
|
Вот вам программа, пользуйтесь.
Цитата:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
StringGrid1: TStringGrid;
Button1: TButton;
StringGrid2: TStringGrid;
Label2: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var b:array of array of integer;
n,m,i,j,k,x:integer;
begin
randomize;
if not TryStrToInt(Edit1.Text,n)
or (StrToInt(Edit1.Text)<1) then
begin
ShowMessage('Количество строк введено неверно, повторите ввод');
Edit1.Clear;
Edit1.SetFocus;
exit
end;
n:=StrToInt(Edit1.Text);
if not TryStrToInt(Edit2.Text,m)
or (StrToInt(Edit2.Text)<1) then
begin
ShowMessage('Количество столбцов введено неверно, повторите ввод');
Edit2.Clear;
Edit2.SetFocus;
exit
end;
m:=StrToInt(Edit2.Text);
StringGrid1.ColCount:=m;
StringGrid1.RowCount:=n;
StringGrid2.ColCount:=m;
StringGrid2.RowCount:=n;
setlength(b,n,m);
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
b[i,j]:=random(100);
StringGrid1.Cells[j,i]:=IntToStr(b[i,j]);
end;
for j:=0 to m-1 do
for i:=0 to n-2 do
for k:=i+1 to n-1 do
if b[i,j]>b[k,j] then
begin
x:=b[i,j];
b[i,j]:=b[k,j];
b[k,j]:=x
end;
for i:=0 to n-1 do
for j:=0 to m-1 do
StringGrid2.Cells[j,i]:=IntToStr(b[i,j])
end;
|
|
|
|