pascal简单的穷举逻辑题

来源:百度知道 编辑:UC知道 时间:2024/05/24 23:53:12
程序要解释
来自不同国家的4位留学生A,B,C,D在一起交谈,他们每人只会中、英、法、日4种语言中的2种,情况是:没有人既能讲日语又能讲法语;A能讲日语,D不会日语,但A和D能互相交谈,B不8会英语,但A和C交谈时却要B当翻译;B,C,D3人想互相交谈,但找不到共同的语言;只有一种语言3人都会。请编程确定这四人分别会哪两种语言。

【Code One】
var f:array[1..4,1..4]of boolean;

function check(a,b:longint):boolean;
var i:longint;
begin
check := false;
for i := 1 to 4 do
if f[a,i] = f[b,i] then exit(true);
end;

function checkjf:boolean;
var i:longint;
begin
checkjf := true;
for i := 1 to 4 do
if f[i,4] and f[i,3] then exit(false);
end;

function checkbcd:boolean;
var i:longint;
begin
checkbcd := true ;
for i := 1 to 4 do
if f[2,i] and f[3,i] and f[4,i] then exit(false);
end;

function check3:boolean;
var i,tot:longint;
begin
tot := 0;
for i := 1 to 4 do
if ord(f[1,i])+ord(f[2,i])+ord(f[3,i])+ord(f[4,i]) =3 then inc (tot);
if tot =1 then exit(true)
else exit(false);
end;
procedure run(x:longint);
var i,j:longint;
begin
if (x = 5) and checkjf
and