![Старый](images/statusicon/post_old.gif)
08.05.2017, 05:47
|
Модератор
|
|
Регистрация: 17.04.2008
Сообщения: 8,048
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
|
|
Ну, например, так:
Код:
type
TDynIntMatrix = Array Of Array Of Integer;
function GetPositiveNum(A : TDynIntMatrix) : Integer;
var
I, J : Integer;
mI, mJ : Integer;
begin
Result := 0;
// Top-Left item - current min item
mI := Low(A);
mJ := Low(A[mI]);
// Search for min item
For I := Low(A) To High(A) Do
For J := Low(A[i]) To High(A[i]) Do
If A[I,J] < A[mI,mJ] Then
Begin
mI := I;
mJ := J;
End;
// Cont positive items
For I := mI To High(A) Do
For J := Low(A[i]) To High(A[i]) Do
Begin
If (I = mI) And (J <= mJ) Then Continue; // Before min item
If A[I,J] > 0 Then Inc(Result); // positive item - increase counter
End;
end;
procedure RandomInitArray(var A : TDynIntMatrix; AI, AJ : Integer);
var
I, J : Integer;
begin
SetLength(A,AI,AJ);
For I := Low(A) To High(A) Do
For J := Low(A[i]) To High(A[i]) Do
A[i,J] := Random(100)-50; // Generate random value -50..49
end;
procedure TForm1.Button1Click(Sender: TObject);
var
M1 : TDynIntMatrix;
M2 : TDynIntMatrix;
S : String;
begin
RandomInitArray(M1,5,10);
RandomInitArray(M2,10,5);
S := 'Positive item after min item count.'#13#10;
S := S + Format('M1 : %d'#13#10,[GetPositiveNum(M1)]);
S := S + Format('M2 : %d',[GetPositiveNum(M2)]);
ShowMessage(S);
end;
|