| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 555 人关注过本帖
标题:教教我
只看楼主 加入收藏
makewelldone
Rank: 1
来 自:江苏南京
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-9-25
收藏
 问题点数:0 回复次数:9 
教教我
我有一个问题,请各位大哥教教我,从1到期10 任意取4个数,用+,—,*,/,()组合计算结果为24,这次的数,不次不在用,请各位大哥教教小弟
搜索更多相关主题的帖子: 大哥 
2007-06-06 10:56
西山居士
Rank: 4
等 级:贵宾
威 望:11
帖 子:581
专家分:0
注 册:2007-4-21
收藏
得分:0 

Public Function f(ByVal m As Integer, ByVal x As Single, ByVal y As Single) As Single
Select Case m
Case 1
f = x + y
Case 2
f = x - y
Case 3
f = x * y
Case 4
f = x / y
End Select
End Function

Private Sub Command1_Click()
Dim s(1 To 4) As String
Dim cc1 As String
Dim tt1, tt2 As String
Dim a(1 To 7) As Single
Dim i, j, k, m, n, b, c, p, x, res As Integer
s(1) = "+"
s(2) = "-"
s(3) = "*"
s(4) = "/"
t = 0
res = 0
a(1) = Val(Combo1.Text)
a(2) = Val(Combo2.Text)
a(3) = Val(Combo3.Text)
a(4) = Val(Combo4.Text)

For i = 1 To 4
For j = 1 To 4
If j <> i Then
For m = 1 To 4
If ((m <> 4) Or a(j) <> 0) Then
a(5) = f(m, a(i), a(j))
For k = 1 To 5
If ((k <> i) And (k <> j)) Then
For b = 1 To 5
If ((b <> i) And (b <> j) And (b <> k)) Then
For n = 1 To 4
If ((n <> 4) Or (a(b) <> 0)) Then
a(6) = f(n, a(k), a(b))
For p = 1 To 6
If ((p <> i) And (p <> j) And (p <> k) And (p <> b)) Then
For c = 1 To 6
If ((c <> i) And (c <> j) And (c <> k) And (c <> b) And (c <> p)) Then
For x = 1 To 4
If ((x <> 4) Or (a(c) <> 0)) Then
a(7) = f(x, a(p), a(c))
If ((Abs(a(7) - 24)) < 0.0001) Then
res = 1
Exit For
End If
End If
Next x
End If
If res = 1 Then Exit For
Next c
End If
If res = 1 Then Exit For
Next p
End If
If res = 1 Then Exit For
Next n
End If
If res = 1 Then Exit For
Next b
End If
If res = 1 Then Exit For
Next k
End If
If res = 1 Then Exit For
Next m
End If
If res = 1 Then Exit For
Next j
If res = 1 Then Exit For
Next i
If res = 0 Then Text1.Text = "无解!"
If res = 1 Then
If k <> 5 And b <> 5 Then
tt1 = CStr(a(i)) + s(m) + CStr(a(j))
tt2 = CStr(a(k)) + s(n) + CStr(a(b))
If ((x = 3 Or x = 4) And (m = 1 Or m = 2) Or (c = 5 And (x = 2 Or x = 4))) Then
tt1 = "(" + tt1 + ")"
End If
If ((x = 3 Or x = 4) And (n = 1 Or n = 2) Or (p = 5 And (x = 2 Or x = 4))) Then
tt2 = "(" + tt2 + ")"
End If
If (p = 5) Then
cc1 = tt1 + s(x) + tt2
End If
If (c = 5) Then
cc1 = tt2 + s(x) + tt1
End If
Else
If (((n = 3 Or n = 4) And (m = 1 Or m = 2)) Or (b = 5 And (n = 2 Or n = 4))) Then
tt1 = "(" + CStr(a(i)) + s(m) + CStr(a(j)) + ")"
Else
tt1 = CStr(a(i)) + s(m) + CStr(a(j))
End If
If (k = 5) Then
tt2 = tt1 + s(n) + CStr(a(b))
End If
If (b = 5) Then
tt2 = CStr(a(k)) + s(n) + tt1
End If
If (((x = 3 Or x = 4) And (n = 1 Or n = 2)) Or (c = 5 And (x = 2 Or x = 4))) Then
tt2 = "(" + tt2 + ")"
End If
If (p = 6) Then
cc1 = tt2 + s(x) + CStr(a(c))
End If
If (c = 6) Then
cc1 = CStr(a(p)) + s(x) + tt2
End If
End If
Text1.Text = cc1
Debug.Print i, j, k, b, p, c, m, n, x
End If

End Sub


2007-06-06 11:17
makewelldone
Rank: 1
来 自:江苏南京
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-9-25
收藏
得分:0 
你运行过了没有,还成功了?
2007-06-06 15:34
西山居士
Rank: 4
等 级:贵宾
威 望:11
帖 子:581
专家分:0
注 册:2007-4-21
收藏
得分:0 
以下是引用makewelldone在2007-6-6 15:34:18的发言:
你运行过了没有,还成功了?

有你这样问问题的吗?你自己不试就反问?请记住我,也记住我的话:
——不能用的代码我是从来不给别人的!


2007-06-06 16:53
wangwang3504
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-5-21
收藏
得分:0 

2007-06-06 19:25
lthiy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:9
帖 子:849
专家分:0
注 册:2007-4-4
收藏
得分:0 
也来学习一下

2007-06-06 21:06
黑暗公爵
Rank: 1
等 级:新手上路
威 望:1
帖 子:46
专家分:0
注 册:2007-5-31
收藏
得分:0 
可以用
试验了

头发遮住眼睛,身心坠入冥冥,世间万千烦扰,我自成竹在胸。
2007-06-07 09:32
编程战神$
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-5-27
收藏
得分:0 
厉害
2007-06-07 14:52
z8520134679
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-6-6
收藏
得分:0 
2007-06-07 15:08
wangwang3504
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-5-21
收藏
得分:0 

2007-06-07 15:58
快速回复:教教我
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018471 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved