首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

pascal逻辑判断求解解决思路

2012-05-28 
pascal逻辑判断求解刘,马,张三家每家有一个孩子,名字是小芳(女),小青(女),小龙(男),三家的妈妈是赵林,李君

pascal逻辑判断求解
刘,马,张三家每家有一个孩子,名字是小芳(女),小青(女),小龙(男),三家的妈妈是赵林,李君和方华,还知道:刘和李君的孩子都是女儿;马的女儿不是小青;张和方华不是一家;请问三家的成员各是谁?

请编出完整的程序

有说用多重循环,使用ord判断
有说用三个数组表示父亲组、母亲组、孩子组

请大虾指教

[解决办法]
马的女儿不是小青 

那马的女儿是小芳 咯?

[解决办法]
{
写了个程序,不知符合你的要求不

}

program Family_Unit;

{$APPTYPE CONSOLE}

uses
SysUtils;
  
type Father = record
name : WideString;
end;

type Mother = Record
name : WideString;
end;

type Child=Record
name : WideString;
Sex : Boolean; //True:男 False:女
end;

type Family=record
F : Father;
M : Mother;
C : Child;
end;

var
Fs : Array[1..3] of Father;
Ms : Array[1..3] of Mother;
Cs : Array[1..3] of Child;
Famis : Array[1..3] of Family;
procedure Init;
begin
FS[1].name := '刘';
FS[2].name := '马';
FS[3].name := '张';
MS[1].name := '赵林';
MS[2].name := '李君';
MS[3].name := '方华';

CS[1].name := '小芳';
CS[1].Sex := False;

CS[2].name := '小青';
CS[2].Sex := False;
 
CS[3].name := '小龙';
CS[3].Sex := True;
end;
function IsFamily(F:Father;M:Mother;C:Child):Boolean;
begin
Result := False;
if (M.name = '李君') and (C.Sex) then
Exit;
{张和方华不是一家}
if (F.name = '张') and (M.name = '方华') then
Exit;

if (F.name = '刘') then
{刘的是女儿}
begin
if not C.Sex then
Result := True;
end;
{马家}
if (F.name = '马') then
{马的女儿不是小青}
begin
if (C.name = '小青') or (C.Sex) then
Exit
else
Result := True;
end;
{张家 : 应该是男孩吧,不知道根据你的表达,我理解对否}
if F.name = '张' then
if C.Sex then
Result := True;
end;

var
i , j , k : Integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
Init;
for i := 1 to 3 do
for j := 1 to 3 do
for k := 1 to 3 do
begin
if IsFamily(Fs[i],Ms[j],Cs[k]) then
WriteLn(Fs[i].name + ' ' + Ms[j].name + ' ' + Cs[k].name);
end;
Readln(i);
end.

热点排行