16,748
社区成员
发帖
与我相关
我的任务
分享
var
a: array[1..6] of Boolean;
i, j, k, l, m, n: Boolean;
function judge: Boolean;
begin
Result := False;
if not (a[1] or a[2]) then Exit; //a[1] a[2]至少一个凶手
if a[1] and a[4] then Exit; //a[1] a[4]不可能同时作案
if a[2] xor a[3] then Exit; //a[2] a[3]要么同时作案 要么都不作案
if not (a[3] xor a[4]) then Exit; //a[3] a[4]只有一个作案
if not a[4] and a[5] then Exit; //a[4]没做 a[5]也不可能做
if ((a[1] and a[5] and a[6])) or
(not (a[1] or a[5] or a[6])) or
(a[1] xor a[5] xor a[6]) then Exit;
Result := True;
end;
begin
Edit1.Clear;
for i := False to True do
for j := False to True do
for k := False to True do
for l := False to True do
for m := False to True do
for n := False to True do
begin
a[1] := i;
a[2] := j;
a[3] := K;
a[4] := l;
a[5] := m;
a[6] := n;
if judge then
begin
Edit1.Text := Edit1.Text + IntToStr(Ord(A[1]));
Edit1.Text := Edit1.Text + IntToStr(Ord(A[2]));
Edit1.Text := Edit1.Text + IntToStr(Ord(A[3]));
Edit1.Text := Edit1.Text + IntToStr(Ord(A[4]));
Edit1.Text := Edit1.Text + IntToStr(Ord(A[5]));
Edit1.Text := Edit1.Text + IntToStr(Ord(A[6]));
end;
end;
end;
var
a: array[1..6] of Boolean;
procedure test(b: array of Boolean);
begin
ShowMessage(Format('%d,%d', [Low(b), High(b)])); // 测试的结果是0,5。这样看来,动态数组参数并非原来的[1..6]
end;
begin
test(a);
end;
function Check: Boolean;
begin
Result := (Ord(b[1]) + Ord(b[2]) >= 1) and //1:b[1] b[2]至少一个凶手
(not (b[1] and b[4])) and //2:b[1] b[4]不可能同时作案
(b[2] = b[3]) and //3:b[2] b[3]要么同时作案 要么都不作案
(Ord(b[3]) + Ord(b[4]) = 1) and //4:b[3] b[4]只有一个作案
(b[4] or (not b[4] and not b[5])) and //5:b[4] 没做 b[5]也不可能做
(Ord(b[1]) + Ord(b[5]) + Ord(b[6]) = 2); //6:b[1] b[5] b[6]有两个人作案
end;
var
b: array[1..6] of Boolean;
function Check: Boolean;
begin
Result := (Ord(b[1]) + Ord(b[2]) >= 1) and //1:b[1] b[2]至少一个凶手
(not (b[1] and b[4])) and //2:b[1] b[4]不可能同时作案
(b[2] <> b[3]) and //3:b[2] b[3]要么同时作案 要么都不作案
(Ord(b[3]) + Ord(b[4]) = 1) and //4:b[3] b[4]只有一个作案
(not (not b[4] and not b[5])) and //5:b[4] 没做 b[5]也不可能做
(Ord(b[1]) + Ord(b[5]) + Ord(b[6]) = 2); //6:b[1] b[5] b[6]有两个人作案
end;
var
I, J: Integer;
S: string;
begin
Edit1.Clear;
FillChar(b[1], SizeOf(b), 0);
//00000000 -> 00111111// 二进制
for I := 0 to $3F do
begin
for J := 0 to 5 do
b[J + 1] := I and (1 shl J) <> 0;
if Check then
begin
S := '';
for J := 0 to 5 do
S := S + IntToStr(Ord(b[J + 1]));
Edit1.Text := S;
end;
end;
end;