新建一工程,把下面代码拷进Form1,运行即可
Option Explicit
'---------------------判断条件------------
'1 英国人住红色房子 cYG=fRed
'2 瑞典人养狗 cRD=wDog
'3 丹麦人喝茶 cDM=jTea
'4 绿色房子在白色房子左面 fGreen=fWhite-1
'5 绿色房子主人喝咖啡 fGreen=jCoffee
'6 抽Pall Mall香烟的人养鸟 yPallMall=wBird
'7 黄色房子主人抽Dunhill香烟 fYellow=yDunhill
'8 住在中间房子的人喝牛奶 jMilk=3
'9 挪威人住第一间房 cNW=1
'10 抽Blends香烟的人住在养猫的人隔壁 Abs(yBlens-wCat)=1
'11 养马的人住抽Dunhill香烟的人隔壁 Abs(wHorse-yDunhill)=1
'12 抽Blue Master的人喝啤酒 yBlueMaster=jBeer
'13 德国人抽Prince香烟 cDG=yPrince
'14 挪威人住蓝色房子隔壁 Abs(cNW-fBlue)=1
'15 抽Blends香烟的人有一个喝水的邻居 Abs(yBlends-jWater)=1
'---------------------相关要素---------------------
'绿房子 蓝房子 红房子 黄房子 白房子
'挪威人 德国人 英国人 丹麦人 瑞典人
'咖啡 水 牛奶 茶 啤酒
'PALLMALL PRINCE Blens DUNHILL BLUE MASTER
'鸟 猫 马 鱼 狗
'变量声明
Dim cDG, cDM, cNW, cRD, cYG '国籍
Dim fBlue, fGreen, fRed, fWhite, fYellow '房子
Dim jBeer, jCoffee, jMilk, jTea, jWater '酒
Dim wBird, wCat, wDog, wFish, wHorse '宠物
Dim yBlends, yBlueMaster, yDunhill, yPallMall, yPrince '烟
Private Sub PLYan() '全排列烟
'yBlends , yBlueMaster, yDunhill, yPallMall, yPrince '烟
'yBlueMaster=jBeer
'yDunhill=fYellow
'yPallMall=wBird
'yPrince=cDG
'Abs(yBlens-wCat)=1
'Abs(yBlends-jWater)=1
'Abs(wHorse-yDunhill)=1
Dim i As Integer
Dim j As Integer
Dim s As String
For yBlends = 1 To 5
If Abs(yBlends - wCat) = 1 And Abs(yBlends - jWater) = 1 Then
yBlueMaster = jBeer
If yBlueMaster <> yBlends Then
yDunhill = fYellow
If yDunhill <> yBlends And yDunhill <> yBlueMaster And Abs(wHorse - yDunhill) = 1 Then
yPallMall = wBird
If yPallMall <> yBlends And yPallMall <> yBlueMaster And yPallMall <> yDunhill Then
yPrince = 15 - yBlends - yBlueMaster - yDunhill - yPallMall
If yPrince = cDG Then
' print cDG, cDM, cNW, cRD, cYG
' print fBlue, fGreen, fRed, fWhite, fYellow
' print jBeer, jCoffee, jMilk, jTea, jWater
' print wBird, wCat, wDog, wFish, wHorse
' print yBlends, yBlueMaster, yDunhill, yPallMall, yPrince
'print cDG, cDM, cNW, cRD, cYG
s = ""
For i = 1 To 5
If cDG = i Then s = s & "德国 "
If cDM = i Then s = s & "丹麦 "
If cNW = i Then s = s & "挪威 "
If cRD = i Then s = s & "瑞典 "
If cYG = i Then s = s & "英国 "
Next i
Print s
'print fBlue, fGreen, fRed, fWhite, fYellow
s = ""
For i = 1 To 5
If fBlue = i Then s = s & "蓝 "
If fGreen = i Then s = s & "绿 "
If fRed = i Then s = s & "红 "
If fWhite = i Then s = s & "白 "
If fYellow = i Then s = s & "黄 "
Next i
Print s
'print jBeer, jCoffee, jMilk, jTea, jWater
s = ""
For i = 1 To 5
If jBeer = i Then s = s & "啤酒 "
If jCoffee = i Then s = s & "咖啡 "
If jMilk = i Then s = s & "牛奶 "
If jTea = i Then s = s & "茶 "
If jWater = i Then s = s & "水 "
Next i
Print s
'print wBird, wCat, wDog, wFish, wHorse
s = ""
For i = 1 To 5
If wBird = i Then s = s & "鸟 "
If wCat = i Then s = s & "猫 "
If wDog = i Then s = s & "狗 "
If wFish = i Then s = s & "鱼 "
If wHorse = i Then s = s & "马 "
Next i
Print s
'print yBlends, yBlueMaster, yDunhill, yPallMall, yPrince
s = ""
For i = 1 To 5
If yBlends = i Then s = s & "Blends "
If yBlueMaster = i Then s = s & "BlueMaster "
If yDunhill = i Then s = s & "Dunhill "
If yPallMall = i Then s = s & "PallMall "
If yPrince = i Then s = s & "Prince "
Next i
Print s
If cDG = wFish Then s = "德国人养鱼"
If cDM = wFish Then s = "丹麦人养鱼"
If cNW = wFish Then s = "挪威人养鱼"
If cRD = wFish Then s = "瑞典人养鱼"
If cYG = wFish Then s = "英国人养鱼"
Print "-------------------------------------------------------------------------"
Print s
End If
End If
End If
End If
End If
Next yBlends
End Sub
Private Sub PLChWu() '全排列宠物
'wBird, wCat, wDog, wFish, wHorse '宠物
'wDog=cRD
wDog = cRD
For wBird = 1 To 5
For wCat = 1 To 5
If wCat <> wBird Then
If wDog <> wBird And wDog <> wCat Then
For wFish = 1 To 5
If wFish <> wBird And wFish <> wCat And wFish <> wDog Then
wHorse = 15 - wBird - wCat - wDog - wFish
PLYan
End If
Next wFish
End If
End If
Next wCat
Next wBird
End Sub
Private Sub PLJiu() '全排列酒
'jBeer, jCoffee, jMilk, jTea, jWater '酒
'jCoffee=fGreen
'jMilk=3
'jTea=cDM
jMilk = 3
jTea = cDM
For jBeer = 1 To 5
jCoffee = fGreen
If jCoffee <> jBeer Then
If jMilk <> jBeer And jMilk <> jCoffee Then
If jTea <> jBeer And jTea <> jCoffee And jTea <> jMilk Then
jWater = 15 - jBeer - jCoffee - jMilk - jTea
PLChWu
End If
End If
End If
Next jBeer
End Sub
Private Sub PLFangZi() '全排列房子
'fBlue, fGreen, fRed, fWhite, fYellow '房子
'fRed=cYG
'fWhite=fGreen+1
'Abs(cNW-fBlue)=1
For fBlue = 1 To 5
If Abs(cNW - fBlue) = 1 Then
For fGreen = 1 To 5
If fGreen <> fBlue Then
fRed = cYG
If fRed <> fBlue And fRed <> fGreen Then
fWhite = fGreen + 1
If fWhite <> fBlue And fWhite <> fRed And fWhite < 6 Then
fYellow = 15 - fBlue - fGreen - fRed - fWhite
PLJiu
End If
End If
End If
Next fGreen
End If
Next fBlue
End Sub
Private Sub PLGuoJI() '全排列国籍
' cDG, cDM, cNW, cRD, cYG
'cNW=1
cNW = 1
For cDG = 2 To 5
For cDM = 2 To 5
If cDM <> cDG Then
For cRD = 2 To 5
If cRD <> cDM And cRD <> cDG Then
cYG = 15 - cDG - cDM - cNW - cRD
PLFangZi
End If
Next cRD
End If
Next cDM
Next cDG
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
PLGuoJI
End Sub