1. 四大淡水湖的排序

1. 有4个学生,上地理课时提出我国四大淡水湖的排序如下。
   甲:洞庭湖最大,洪泽湖最小,鄱阳湖第三;
   乙:洪泽湖最大,洞庭湖最小,鄱阳湖第二,太湖第三;
   丙:红泽湖最小,洞庭湖第三;
   丁:鄱阳湖最大,太湖最小,洪泽湖第二,洞庭湖第三;
对于各个湖泊应处的地位,每个人只说对了一个。
根据以上情况,编一个程序,让计算机判断各个湖泊应处在第几位。
program exInference1_1;
var
    py, dt, th, hz : integer;
begin
     writeln(' py dt th hz');
     for py := 1 to 4 do
         for dt := 1 to 4 do
             for th := 1 to 4 do
                 for hz := 1 to 4 do
                 begin
                      if  ( ord(dt = 1) + ord(hz = 4) + ord(py = 3) = 1 )
                      and ( ord(hz = 1) + ord(dt = 4) + ord(py = 2) + ord(th = 3) = 1 )
                      and ( ord(hz = 4) + ord(dt = 3) = 1 )
                      and ( ord(py = 1) + ord(th = 4) + ord(hz = 2) + ord(dt = 3) = 1 )
                      and ( py+dt+th+hz = 10 ) then
                          writeln(py:3, dt:3, th:3, hz:3);
                 end;
     readln;
end.

上面的程序没有考虑到大小相等的情况。下面的考虑了。

program exInference1_2;
var
    py, dt, th, hz : integer;
begin
     writeln(' py dt th hz');
     for py := 1 to 4 do
         for dt := 1 to 4 do
             if py <> dt then
             for th := 1 to 4 do
                 if (th <> py) and (th <> dt) then
                 begin
                      hz := 10-py-dt-th;
                      if  ( ord(dt = 1) + ord(hz = 4) + ord(py = 3) = 1 )
                      and ( ord(hz = 1) + ord(dt = 4) + ord(py = 2) + ord(th = 3) = 1 )
                      and ( ord(hz = 4) + ord(dt = 3) = 1 )
                      and ( ord(py = 1) + ord(th = 4) + ord(hz = 2) + ord(dt = 3) = 1 ) then
                          writeln(py:3, dt:3, th:3, hz:3);
                 end;
     readln;
end.

posted @ 2010-01-01 21:12  SmartIOI  阅读(1865)  评论(0)    收藏  举报
本站采用CC授权如需转载、引用文章,请务必附上作者及来源处。 Creative Commons License