回复 1# pusofalse
写个程序来判断,p版及各位请勿见笑:
Dim $a,$b,$ab,$ba;$a、$b表示a、b的诚实度,诚实记为1,否则为-1;,$ab为$a描述的b是否诚实,诚实记为1,不诚实记为-1,$ba为$b描述的a是否诚实,诚实记为1,不诚实记为-1
Global $count_1=0,$count_2=0;计数器
;如第一题,a: b说的是真话,故 $ab=1. b: a说的是假话,故$ba=-1,以下函数记为panduan(1,-1)
panduan(1,-1)
Func panduan($ab,$ba)
$a=1;假设a是诚实的
$b=$a*$ab;b的诚实与否等于a的诚实与否与a所说的乘积
$a=$b*$ba;a的诚实与否等于b的诚实与否与b所说的乘积
If $a<>1 Then $count_1+=1;MsgBox(0,0,"假设错误");反推回去验证a是否诚实,如果验证错误,那么假设错误,计数器+1
$a=-1;假设a是不诚实的
$b=$a*$ab
$a=$b*$ba
If $a<>-1 Then $count_2+=1;MsgBox(0,0,"假设错误")
If $count_1+$count_2=2 Then
MsgBox(0,0,"两人都说假话")
ElseIf $count_1+$count_2=0 Then
MsgBox(0,0,"两人都说真话")
Else
If $count_1=1 And $count_2=0 Then MsgBox(0,0,"a说真话,b说假话")
If $count_1=0 And $count_2=1 Then MsgBox(0,0,"b说真话,a说假话")
EndIf
EndFunc
|