在下面的示例中:
matrix[column][row]
是“myMatrix”类型的结构。只需遍历第一个数组并将其发送到您的测试函数。
此外,在测试功能中,请确保将结果设置为 false 开始!
type
myArray = array [1..10] of integer;
myMatrix = array[1..10] of myArray;
var
matrix: myMatrix;
function noRepeat(const A: myArray): Boolean;
var
i: integer;
begin
//Result := true; //?
Result := false;
for i:=1 to high(A) do
for j := i + 1 to high(A) do
if (A[i] = A[j]) then
Result := true;
end;
procedure sendColumn;
var
b, wasRepeat: boolean;
i: Integer;
Begin
for i := low(matrix) to high(matrix) do
Begin
b := noRepeat(matrix[i]);
if b then
wasRepeat := true;
End;
End;
如果它是行专业的,那么您必须告知测试例程您要测试哪一列。
type
myArray = array [1..10] of integer;
myMatrix = array[1..10] of myArray;
var
matrix: myMatrix;
function noRepeat(const A: myMatrix; Col: Integer): Boolean;
var
i, j: integer;
begin
Result := false;
for i := low(A) to high(A) do
for j := i + low(A) to high(A) do
if (A[i][Col] = A[j][Col]) then
Result := true;
end;
procedure sendColumn;
var
b, wasRepeat: boolean;
i: Integer;
Begin
for i := 1 to 10 do
Begin
b := noRepeat(matrix, i);
if b then
wasRepeat := true;
End;
End;