a3d*_*fcv 1 arrays delphi pascal function matrix
我有一个函数来检查数组中是否有重复数据;这看起来像下图所示。任务是使用该函数查找矩阵中没有重复数据的列。问题是如何将矩阵的列传递给该函数。
PS 我正在使用 Pascal/Delphi
type
myArray = array [1..10] of integer;
function noRepeat(A: myArray; n: integer): Boolean;
var
i: integer;
begin
Result := true;
for i:=1 to n do
for j := i + 1 to n do
if (A[i] = A[j]) then
Result := true;
end;
Run Code Online (Sandbox Code Playgroud)
在下面的例子中:
matrix[column][row]
Run Code Online (Sandbox Code Playgroud)
是 '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;
Run Code Online (Sandbox Code Playgroud)
如果是行专业,那么您必须通知测试例程您要测试哪一列。
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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6414 次 |
| 最近记录: |