P
plenilune168
Unregistered / Unconfirmed
GUEST, unregistred user!
15分钟内搞定:
const PeopleArr:array[1..3] of string=('Mary','John','Peter');
HairArr:array[1..3] of string=('红色','棕色','金色');
AgeArr:array[1..3] of string=('13','14','15');
var h1,h2,h3,a1,a2,a3:integer;
begin
for h1:=1 to 3 do
for h2:=2 to 3 do //John不是红色的头发,从2开始
if (h1<>h2) and (6-h1-h2<>3) then //Peter不是金色的头发
for a1:=1 to 3 do
for a2:=1 to 3 do
if a1<>a2 then
begin
h3:=6-h1-h2;
a3:=6-a1-a2;
if ((a1=1) and (h1=3) or
(a2=1) and (h2=3)) //最小的孩子是金色的头发,Peter不是金发不用判断
and
(AgeArr[a2]>AgeArr[a3]) //John比Peter大
then
begin
Showmessage('Mary: '+HairArr[h1]+' '+AgeArr[a1]+#13+
'John: '+HairArr[h2]+' '+AgeArr[a2]+#13+
'Peter:'+HairArr[h3]+' '+AgeArr[a3]
);
end;
end;
end;
Mary 金色 13
John 棕色 15
Peter 红色 14
const PeopleArr:array[1..3] of string=('Mary','John','Peter');
HairArr:array[1..3] of string=('红色','棕色','金色');
AgeArr:array[1..3] of string=('13','14','15');
var h1,h2,h3,a1,a2,a3:integer;
begin
for h1:=1 to 3 do
for h2:=2 to 3 do //John不是红色的头发,从2开始
if (h1<>h2) and (6-h1-h2<>3) then //Peter不是金色的头发
for a1:=1 to 3 do
for a2:=1 to 3 do
if a1<>a2 then
begin
h3:=6-h1-h2;
a3:=6-a1-a2;
if ((a1=1) and (h1=3) or
(a2=1) and (h2=3)) //最小的孩子是金色的头发,Peter不是金发不用判断
and
(AgeArr[a2]>AgeArr[a3]) //John比Peter大
then
begin
Showmessage('Mary: '+HairArr[h1]+' '+AgeArr[a1]+#13+
'John: '+HairArr[h2]+' '+AgeArr[a2]+#13+
'Peter:'+HairArr[h3]+' '+AgeArr[a3]
);
end;
end;
end;
Mary 金色 13
John 棕色 15
Peter 红色 14