Характеристикой строки назовем наибольшее количество идущих подряд нулей.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
randomize;
with StringGrid1 do
begin
i:=0;
for j:=1 to RowCount-1 do
Cells[i,j]:=IntToStr(j);
j:=0;
for i:=1 to ColCount-1 do
Cells[i,j]:=IntToStr(i);
end;
with StringGrid1 do
For i:=1 to ColCount-1 do
for j:=1 to RowCount-1 do
begin
Cells[i,j]:=intToStr(random(2));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,t,j,k,n,l,vd:integer;
a,b:array of integer;
begin
for vd:=1 to StringGrid1.RowCount-1 do
begin
SetLength(a,StringGrid1.RowCount-1);
k:=0;
l:=0;
i:=0;
repeat
i:=i+1;
for j:=1 to StringGrid1.ColCount-1 do
begin
if StrtoInt(StringGrid1.Cells[j,i])=0 then
begin
k:=k+1;
if k>l then
l:=k;
end
else
k:=0;
end;
a[i-1]:=l;
l:=0;
k:=0;
until i=StringGrid1.RowCount-1;
SetLength(b,StringGrid1.ColCount);
n:=1;
repeat
if a[n-1]>a[n] then
begin
for t:=1 to Length(b)-1 do
b[t]:=StrToInt(StringGrid1.Cells[t,n]);
StringGrid1.Rows[n]:=StringGrid1.Rows[n+1];
for t:=1 to Length(b)-1 do
StringGrid1.Cells[t,n+1]:=IntToStr(b[t]);
end;
n:=n+1;
until n=Length(a);
end;
end;
end.