本帖最后由 rolaka 于 2009-12-2 20:59 编辑
第一个研究中...= =!
第二道...只写完检测部分 生成答案的递归没来得及写完;首先 生成5个人 5栋房子
;房子[0国籍][1房子颜色][2饮料][3香烟][4宠物]
Local $house[5][5]
;颜色
Global $h[5] = ["黄", "蓝", "红", "绿", "白"]
;国籍
Global $c[5] = ["挪威人", "丹麦人", "英国人", "德国人", "瑞典人"]
;饮料
Global $d[5] = ["水", "茶", "牛奶", "咖啡", "啤酒"]
;香烟
Global $s[5] = ["Dunhill", "Blends", "Pall Mall", "Prince", "Blue Master"]
;宠物
Global $p[5] = ["猫", "马", "鸟", "鱼", "狗"]
;开始生成数组...这里直接提交答案 应该是个答案数组生成...这个还没写...
For $i = 0 To 4
$house[$i][0] = $c[$i]
$house[$i][1] = $h[$i]
$house[$i][2] = $d[$i]
$house[$i][3] = $s[$i]
$house[$i][4] = $p[$i]
Next
MsgBox (0, "", Check($house))
;首先 写一个检测函数
Func Check($house)
;1、英国人住红色房子
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][0] == "英国人" Then
If $house[$i][1] == "红" Then
ExitLoop
EndIf
EndIf
Next
;2、瑞典人养狗
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][0] == "瑞典人" Then
If $house[$i][4] == "狗" Then
ExitLoop
EndIf
EndIf
Next
;3、丹麦人喝茶
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][0] == "丹麦人" Then
If $house[$i][2] == "茶" Then
ExitLoop
EndIf
EndIf
Next
;4、绿色房子在白色房子左面
For $i = 0 To 4
If $i == 4 Then
Return 0
EndIf
If $house[$i][1] == "绿" Then
If $house[$i+1][1] == "白" Then
ExitLoop
EndIf
EndIf
Next
;5、绿色房子主人喝咖啡
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][1] == "绿" Then
If $house[$i][2] == "咖啡" Then
ExitLoop
EndIf
EndIf
Next
;6、抽Pall Mall 香烟的人养鸟
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][3] == "Pall Mall" Then
If $house[$i][4] == "鸟" Then
ExitLoop
EndIf
EndIf
Next
;7、黄色房子主人抽Dunhill 香烟
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][3] == "Pall Mall" Then
If $house[$i][4] == "鸟" Then
ExitLoop
EndIf
EndIf
Next
;8、住在中间房子的人喝牛奶
If $house[2][2] <> "牛奶" Then
Return 0
EndIf
;9、 挪威人住第一间房
If $house[0][0] <> "挪威人" Then
Return 0
EndIf
;10、抽Blends香烟的人住在养猫的人隔壁
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][3] == "Blends" Then
If $i > 0 Then
If $house[$i-1][4] == "猫" Then
ExitLoop
EndIf
EndIf
If $i < 0 Then
If $house[$i+1][4] == "猫" Then
ExitLoop
EndIf
EndIf
EndIf
Next
;11、养马的人住抽Dunhill 香烟的人隔壁
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][4] == "马" Then
If $i > 0 Then
If $house[$i-1][3] == "Dunhill" Then
ExitLoop
EndIf
EndIf
If $i < 0 Then
If $house[$i+1][3] == "Dunhill" Then
ExitLoop
EndIf
EndIf
EndIf
Next
;12、抽Blue Master的人喝啤酒
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][3] == "Blue Master" Then
If $house[$i][2] == "啤酒" Then
ExitLoop
EndIf
EndIf
Next
;13、德国人抽Prince香烟
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][0] == "德国人" Then
If $house[$i][3] == "Prince" Then
ExitLoop
EndIf
EndIf
Next
;14、挪威人住蓝色房子隔壁
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][0] == "挪威人" Then
If $i > 0 Then
If $house[$i-1][1] == "蓝" Then
ExitLoop
EndIf
EndIf
If $i < 5 Then
If $house[$i+1][1] == "蓝" Then
ExitLoop
EndIf
EndIf
EndIf
Next
;15、抽Blends香烟的人有一个喝水的邻居
For $i = 0 To 5
If $i == 5 Then
Return 0
EndIf
If $house[$i][3] == "Blends" Then
If $i > 0 Then
If $house[$i-1][2] == "水" Then
ExitLoop
EndIf
EndIf
If $i < 5 Then
If $house[$i+1][2] == "水" Then
ExitLoop
EndIf
EndIf
EndIf
Next
Return 1
EndFunc
|