刘,马,张三家每家有一个孩子,名字是小芳(女),小青(女),小龙(男),三家的妈妈是赵林,李君和方华,还知道:刘和李君的孩子都是女儿;马的女儿不是小青;张和方华不是一家;请问三家的成员各是谁?请编出完整的程序有说用多重循环,使用ord判断
有说用三个数组表示父亲组、母亲组、孩子组请大虾指教

解决方案 »

  1.   

    终于搞定了,感谢“双燕飞”的帮忙,以下代码可以实现,就是不知道还有更好的方法不
    program ex17;
    uses crt;
    var liu,ma,zhang,xiaofang,qing,xiaolong,zhao,li,fang,i:integer;
        x,y:set of 1..3;begin
      clrscr;
      liu:=1;ma:=2;zhang:=3;
      for xiaofang:=1 to 3 do
        for qing:=1 to 3 do
          for xiaolong:=1 to 3 do
            for zhao:=1 to 3 do
               for li:=1 to 3  do
                 for fang:=1 to 3 do begin
                   x:=[xiaofang,qing,xiaolong];
                   y:=[zhao,li,fang];
                   if (fang=2) and (qing<>2) and (fang<>3) and (qing=1)
                   and (xiaolong=3) and (xiaolong<>li) and (x=[1,2,3]) and (y=[1,2,3]) then begin
                      for i:=1 to 3 do begin
                        if liu=i then write('laoliu ');
                        if ma=i then write('laoma ');
                        if zhang=i then write('laozhang ');
                        if xiaofang=i then write('xiaofang ');
                        if qing=i then write('xiaoqing ');
                        if xiaolong=i then write('xiaolong ');
                        if zhao=i then write('zhaonvshi ');
                        if li=i then write('linvshi ');
                        if fang=i then write('fangnvshi ');
                        writeln('shi yi jia.');
                      end;
                   end;
                 end;        readln;end.请大家继续跟帖,分还没地方给哦,别浪费了
      

  2.   

    {
           写了个程序,不知符合你的要求不}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.