原题如下(英文题目我就不发上来了):
下面有一长串字符"120121222110211",长度为15,它是由若干个0,1,2组成的,我们假设1表示某随机生成的4个小于10的数字的其中前2个数字之和大于另外后2个数字之和,2表示其中前2个数字之和小于另外后2个数字之和,0表示其中前2个数字之和等于另外后2个数字之和:
现在要求您用VB写出程序随即生成这15组数字,共60个数字,每4个数字分1组,而第1组前2位数字之和和后2位数字之和比较的结果正好代表的是"120121222110211"中的第1个数字1,即前之和大于后之和,依次循环下去....(原题是要求C写的,并且不许用笔先构思算法)测试一下自己实现成功花的时间,并贴出各自的算法,我们看看谁的算法最效率,最便捷?如果你解答该题只花了5-10分钟,那你可以去微软公司上班了
如果你解答该题只花了10-30分钟,那你也应该算得上一个精良的VB程序员
如果你解答该题花了30分钟-2小时,那你VB理论学得蛮精通
如果你解答该题花了2小时-1天时间,那你还得加油啊
如果你解答该题花了1天-5天,那你肯定是个新手
如果你根本不会解答该题,那你的潜力将无法估量!当然如果您是高手,绝对这道题目不够刺激的话,那我再加个条件:那就是当2个数字之和大于10时,该和再减10得的数字再与另外2个数字之和(如和大于10,自动减10)进行比较。
此题仅供大家消遣解闷,不存在任何其他之可能目的。
Dim sBase As String
sBase = "120121222110211"
Randomize
Dim TmpS As String, i As Long, L As Long, SS As String, K As Long, M As Long
TmpS = ""
For i = 1 To Len(sBase)
K = Val(Mid(sBase, i, 1))
L = Int(100 * Rnd()): SS = L & ",": M = L
L = Int(100 * Rnd()): SS = SS & L & ",": M = M + L
L = Int(M * Rnd() / 2): SS = SS & L & ",": M = M - L
Select Case K
Case 0:
L = M: SS = SS & L
Case 1:
L = M + Int(10 * Rnd()) + 1: SS = SS & L
Case 2:
L = Int(M * Rnd()) - 1: SS = SS & L
End Select
TmpS = TmpS & SS & Chr(13) & Chr(10)
Next i
Text1.Text = TmpS
End Sub哈哈,<5分钟!!!!
Dim sBase As String
sBase = "120121222110211"
Randomize
Dim TmpS As String, i As Long, L(4) As Long, SS As String, K As Long, j As Long
TmpS = ""
For i = 1 To Len(sBase)
K = Val(Mid(sBase, i, 1))
For j = 0 To 3
L(j) = Int(10 * Rnd())
Next j
If L(0) + L(1) > L(2) + L(3) Then
j = L(0): L(0) = L(2): L(2) = j
j = L(1): L(1) = L(3): L(3) = j
End If
Select Case K
Case 0:
j = L(2) + L(3) - L(0) - L(1)
If j + L(0) >= 10 Then
j = j + L(0) - 9
L(0) = 9
Else
L(0) = L(0) + j
End If
SS = ""
For j = 0 To 3
SS = SS & L(j) & ","
Next j
SS = Left(SS, Len(SS) - 1)
Case 1:
SS = ""
For j = 3 To 0 Step -1
SS = SS & L(j) & ","
Next j
SS = Left(SS, Len(SS) - 1)
Case 2:
SS = ""
For j = 0 To 3
SS = SS & L(j) & ","
Next j
SS = Left(SS, Len(SS) - 1)
End Select
TmpS = TmpS & SS & Chr(13) & Chr(10)
Next i
Text1.Text = TmpS
End Sub
这翻译的还真有点…… 问题。看题目就要n分钟了。
已知:
随即60个数字,每个数字范围0~9
dim Result as string
for i = 0 as int to 14
d1 = 随即产生一个(0~9)的数字
d2 = 随即产生一个(0~9)的数字
d3 = 随即产生一个(0~9)的数字
d4 = 随即产生一个(0~9)的数字
if d1+d2 > d3+d4 then Result = Result & "1"
if d1+d2 < d3+d4 then Result = Result & "2"
if d1+d2 = d3+d4 then Result = Result & "0"
next
Result is the answer that we need.
Randomize
Dim b(15, 4) As Integer, a(15) As Integer
str1 = "120121222110211"
For i = 1 To 15
a(i) = Val(Mid(str1, i, 1))
Next
For i = 1 To 15
Do
For j = 1 To 4
b(i, j) = Int(Rnd * 10)
Next
n1 = b(i, 1) + b(i, 2)
n2 = b(i, 3) + b(i, 4)
If a(i) = 0 And n1 = n2 Or a(i) = 1 And n1 > n2 Or a(i) = 2 And n1 < n2 Then Exit Do
DoEvents
Loop
Next
For i = 1 To 15
For j = 1 To 4
Print b(i, j);
Next
Print
Next
End Sub
Dim baseStr As String
baseStr = "120121222110211"
Dim i As Integer
Dim a As Integer, b As Integer, c As Integer, d As Integer
Dim t As Integer
Dim Rs As String
For i = 1 To 15
t = CInt(Mid(baseStr, i, 1))
Do
a = Round(Rnd() * 9)
b = Round(Rnd() * 9)
c = Round(Rnd() * 9)
d = Round(Rnd() * 9)
Loop While getCode(a + b, c + d) = t
Rs = Rs & CStr(a) & CStr(b) & CStr(c) & CStr(d)
DoEvents
Next i
Label1.Caption = RsEnd SubPrivate Function getCode(ByVal a As Integer, ByVal b As Integer) As Integer
If a > b Then
getCode = 1
Exit Function
ElseIf a < b Then
getCode = 2
Exit Function
Else
getCode = 0
Exit Function
End If
End Function
Randomize
Dim b(15, 4) As Integer, a(15) As String
str1 = "120121222110211"
For i = 1 To 15
a(i) = Mid(str1, i, 1)
Next
For i = 1 To 15
Do
For j = 1 To 4
b(i, j) = Int(Rnd * 10)
Next
n1 = (b(i, 1) + b(i, 2)) Mod 10
n2 = (b(i, 3) + b(i, 4)) Mod 10
If a(i) = "0" And n1 = n2 Or a(i) = "1" And n1 > n2 Or a(i) = "2" And n1 < n2 Then Exit Do
DoEvents
Loop
Next
For i = 1 To 15
For j = 1 To 4
Print b(i, j);
Next
Print
Next
End Sub
Randomize: Dim b(15, 4) As Integer
str1 = "120121222110211"
For i = 1 To 15
For j = 1 To 4
b(i, j) = Int(Rnd * 10)
Next
n1 = (b(i, 1) + b(i, 2)) Mod 10
n2 = (b(i, 3) + b(i, 4)) Mod 10
Select Case Mid(str1, i, 1)
Case "0"
If n1 <> n2 Then i = i - 1
Case "1"
If n1 <= n2 Then i = i - 1
Case "2"
If n1 >= n2 Then i = i - 1
End Select
Next
End Sub
Randomize
Dim sb As String, ar(14) As String, i As Integer, j As Integer, tmpi As String, tmpj As String
sb = "120122102010201"
For i = 0 To Len(sb) - 1
Do Until Len(ar(i)) <> 0
tmpi = Format(Int(Rnd * 99), "00")
tmpj = Format(Int(Rnd * 99), "00")
If (Val(CInt(Left(tmpi, 1)) + CInt(Right(tmpi, 1))) Mod 10) > (Val(CInt(Left(tmpj, 1)) + CInt(Right(tmpj, 1))) Mod 10) Then
If Mid(sb, i + 1, 1) = 2 Then ar(i) = tmpi & tmpj
ElseIf (Val(CInt(Left(tmpi, 1)) + CInt(Right(tmpi, 1))) Mod 10) < (Val(CInt(Left(tmpj, 1)) + CInt(Right(tmpj, 1))) Mod 10) Then
Debug.Print "<"
If Mid(sb, i + 1, 1) = 1 Then ar(i) = tmpi & tmpj
ElseIf (Val(CInt(Left(tmpi, 1)) + CInt(Right(tmpi, 1))) Mod 10) = (Val(CInt(Left(tmpj, 1)) + CInt(Right(tmpj, 1))) Mod 10) Then
Debug.Print "="
If Mid(sb, i + 1, 1) = 0 Then ar(i) = tmpi & tmpj
End If
Loop
Next
For i = 0 To 14
Debug.Print ar(i)
Next
End Sub没有测试,不知这样行不?
Randomize
Dim a(15, 4)
str1 = "120121222110211"
For i = 1 To 15
s = Format$(Rnd * 9999, "0000")
n1 = 0: n2 = 0
n1 = (Val(Mid(s, 1, 1)) + Val(Mid(s, 2, 1))) Mod 10
n2 = (Val(Mid(s, 3, 1)) + Val(Mid(s, 4, 1))) Mod 10
b = Mid(str1, i, 1)
If b = "0" And n1 = n2 Or b = "1" And n1 > n2 Or b = "2" And n1 < n2 Then
Print i, s, Mid(str1, i, 1)
Else
i = i - 1
End If
Next
End Sub
Dim a, b, c, d, i, r, s
s = ""
For i = 1 To 15 '产生60个小于10的数
a = CreateRndNum
b = CreateRndNum
c = CreateRndNum
d = CreateRndNum
Select Case a + b - c - d
Case Is > 0
r = 1
Case Is = 0
r = 0
Case Else
r = 2
End Select
s = s & r
Next i
Debug.Print s
End SubPrivate Function CreateRndNum()
Randomize
Dim x As Integer
x = 0 + 10 * Rnd()
If x > 10 Then x = 10
CreateRndNum = x
End Function
'下面有一长串字符"120121222110211",长度为15,它是由若干个0,1,2组成的,
'我们假设
'1 表示某随机生成的4个小于10的数字的其中前2个数字之和大于另外后2个数字之和,
'2 表示其中前2个数字之和小于另外后2个数字之和,
'0 表示其中前2个数字之和等于另外后2个数字之和:'现在要求您用VB写出程序随即生成这15组数字,共60个数字,
'每4个数字分1组,而第1组前2位数字之和和后2位数字之和比较的结果正好代表的是"120121222110211"中的第1个数字1,
'即前之和大于后之和,依次循环下去....(原题是要求C写的,并且不许用笔先构思算法)Private Sub Command1_Click()
Dim BaseString As String
Dim intLen As Long
Dim i As Long
Dim OneStr As String
'--------------------
BaseString = "120121222110211"
intLen = Len(BaseString)
For i = 1 To intLen
OneStr = Mid(BaseString, i, 1)
Debug.Print i, OneStr, GetString(OneStr)
Next i
End Sub
Private Function GetString(Style As String) As String
Dim int1 As Long
Dim int2 As Long
Dim int3 As Long
Dim int4 As Long
Line1:
int1 = Int(Rnd * 10)
int2 = Int(Rnd * 10)
int3 = Int(Rnd * 10)
int4 = Int(Rnd * 10)
Select Case Style
Case "1"
If (int1 + int2) > (int3 + int4) Then
GetString = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case "2"
If (int1 + int2) < (int3 + int4) Then
GetString = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case "0"
If (int1 + int2) = (int3 + int4) Then
GetString = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case Else
GetString = ""
Exit Function
End Select
End Function
'下面有一长串字符"120121222110211",长度为15,它是由若干个0,1,2组成的,
'我们假设
'1 表示某随机生成的4个小于10的数字的其中前2个数字之和大于另外后2个数字之和,
'2 表示其中前2个数字之和小于另外后2个数字之和,
'0 表示其中前2个数字之和等于另外后2个数字之和:'现在要求您用VB写出程序随即生成这15组数字,共60个数字,
'每4个数字分1组,而第1组前2位数字之和和后2位数字之和比较的结果正好代表的是"120121222110211"中的第1个数字1,
'即前之和大于后之和,依次循环下去....(原题是要求C写的,并且不许用笔先构思算法)Private Sub Command1_Click()
Dim BaseString As String
Dim intLen As Long
Dim i As Long
Dim OneStr As String
'--------------------
BaseString = "120121222110211"
intLen = Len(BaseString)
For i = 1 To intLen
OneStr = Mid(BaseString, i, 1)
Debug.Print i, OneStr, "A: " & GetString(OneStr), "B: " & GetString1(OneStr)
Next i
End Sub
Private Function GetString(Style As String) As String
Dim int1 As Long
Dim int2 As Long
Dim int3 As Long
Dim int4 As Long
Line1:
int1 = Int(Rnd * 10)
int2 = Int(Rnd * 10)
int3 = Int(Rnd * 10)
int4 = Int(Rnd * 10)
Select Case Style
Case "1"
If (int1 + int2) > (int3 + int4) Then
GetString = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case "2"
If (int1 + int2) < (int3 + int4) Then
GetString = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case "0"
If (int1 + int2) = (int3 + int4) Then
GetString = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case Else
GetString = ""
Exit Function
End Select
End Function
Private Function GetString1(Style As String) As String
Dim int1 As Long
Dim int2 As Long
Dim int3 As Long
Dim int4 As Long
Dim sum1 As Long
Dim sum2 As Long
Line1:
int1 = Int(Rnd * 10)
int2 = Int(Rnd * 10)
int3 = Int(Rnd * 10)
int4 = Int(Rnd * 10)
sum1 = int1 + int2
sum2 = int3 + int4
If sum1 > 10 Then sum1 = sum1 - 10
If sum2 > 10 Then sum2 = sum2 - 10
Select Case Style
Case "1"
If sum1 > sum2 Then
GetString1 = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case "2"
If sum1 < sum2 Then
GetString1 = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case "0"
If sum1 = sum2 Then
GetString1 = CStr(int1) & CStr(int2) & CStr(int3) & CStr(int4)
Exit Function
Else
GoTo Line1
End If
'////////////////////////////////////////////////////////////////////////////
Case Else
GetString1 = ""
Exit Function
End Select
End Function运行结果:
1 1 A: 7552 B: 3707
2 2 A: 8093 B: 5705
3 0 A: 6491 B: 2332
4 1 A: 5964 B: 6077
5 2 A: 7057 B: 8398
6 1 A: 6984 B: 1976
7 2 A: 2428 B: 5953
8 2 A: 3078 B: 7404
9 2 A: 1592 B: 5952
10 1 A: 2520 B: 8169
11 1 A: 8811 B: 9857
12 0 A: 7649 B: 7492
13 2 A: 0297 B: 5625
14 1 A: 7805 B: 5560
15 1 A: 1201 B: 4557
太new B 了
连续回帖7次!
没有超过30分钟!也许不太快捷吧!Private Sub Command1_Click()
Cls
Dim TempNum1 As Long
Dim TempNum2 As Long
Dim TempNum3 As Long
Dim TempNum4 As Long
Dim Strlong As String
Dim StrTemp As String
Strlong = "120121222110211"
For i = 1 To 15
StrTemp = Mid(Strlong, i, 1)
'Print "StrTemp="; StrTemp
Select Case StrTemp
Case "0" '前两数之和等于后两数
TempNum1 = RndNum
TempNum2 = RndNum
TempNum3 = RndNum
TempNum4 = RndNum
Do While Not (TempNum1 + TempNum2) = (TempNum3 + TempNum4)
TempNum3 = RndNum
TempNum4 = RndNum
Loop
Print "第"; i; "组数是="; StrTemp; " :"; TempNum1; TempNum2; TempNum3; TempNum4
TempNum1 = 0
TempNum2 = 0
TempNum3 = 0
TempNum4 = 0
Case "1" '前两数之和大于后两数
TempNum1 = RndNum
TempNum2 = RndNum
TempNum3 = RndNum
TempNum4 = RndNum
If TempNum1 = TempNum2 Then TempNum2 = RndNum
Do While Not ((TempNum1 + TempNum2) > (TempNum3 + TempNum4))
TempNum3 = RndNum
TempNum4 = RndNum
Loop
Print "第"; i; "组数是="; StrTemp; " :"; TempNum1; TempNum2; TempNum3; TempNum4
TempNum1 = 0
TempNum2 = 0
TempNum3 = 0
TempNum4 = 0
Case "2" '前两数之和小于后两数
TempNum1 = RndNum
TempNum2 = RndNum
TempNum3 = RndNum
TempNum4 = RndNum
If TempNum1 = TempNum2 Then TempNum2 = RndNum
Do While Not ((TempNum1 + TempNum2) < (TempNum3 + TempNum4))
TempNum3 = RndNum
TempNum4 = RndNum
Loop
Print "第"; i; "组数是="; StrTemp; " :"; TempNum1; TempNum2; TempNum3; TempNum4
TempNum1 = 0
TempNum2 = 0
TempNum3 = 0
TempNum4 = 0
End Select
Next
End Sub
Function RndNum() As Long
Randomize Timer
Dim TNum As Long
Do While TNum = 0
TNum = Int((9 * Rnd))
Loop
RndNum = TNum
End Function
回复人: tirone13(?什么?) ( ) 信誉:100 2005-01-26 16:56:00 得分: 0
盖茨读大一时VB还在胎里。
哈哈 估计是某君的作业题了
Private Sub Form_Load()
aa = "120121222110211"
randfournum "0"
End Sub
Function getindexnum(a As String, i As Integer) As Integer
getindexnum = Val(Mid(a, i, 1))
End FunctionSub randfournum(a As String)
Dim i As Integer, j As Integer, n As Integer
Dim tmp As Integer
Dim num(1 To 15, 0 To 3) As Integer
For i = 1 To Len(a)
tmp = getindexnum(a, i)
Randomize
Select Case tmp
Case 1
num(i, 0) = Rnd() * 500
num(i, 1) = Rnd() * 500
num(i, 2) = Rnd() * (num(i, 0) + num(i, 1) - 1)
num(i, 3) = Rnd() * (num(i, 0) + num(i, 1) - num(i, 2) - 1)
Case 2
num(i, 2) = Rnd() * 500
num(i, 3) = Rnd() * 500
num(i, 1) = Rnd() * (num(i, 2) + num(i, 3) - 1)
num(i, 0) = Rnd() * (num(i, 2) + num(i, 3) - num(i, 1) - 1)Case 0
num(i, 0) = Rnd() * 500
num(i, 1) = Rnd() * 500
num(i, 2) = Rnd() * (num(i, 0) + num(i, 1) - 1)
num(i, 3) = num(i, 0) + num(i, 1) - num(i, 2)
End Select
MsgBox num(i, 0) & " " & num(i, 1) & " " & num(i, 2) & " " & num(i, 3)
Next
End Sub
Dim i As Integer, j As Integer
Dim a As Integer, b As Integer, c As Integer, d As Integer
Const str = "120121222110211"
For i = 1 To Len(str)
j = Mid(str, i, 1)
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
d = Int(Rnd * 10)
Select Case j
Case 0
Do While (a + b) - (c + d) <> 0
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
d = Int(Rnd * 10)
Loop
Case 1
Do While (a + b) - (c + d) <> 1
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
d = Int(Rnd * 10)
Loop
Case 2
Do While (a + b) - (c + d) <> -2
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
d = Int(Rnd * 10)
Loop
End Select
Print a & b & c & d
Next i
End Sub一次调试通过,可以去微软上班了!哈哈
Dim M() As String, ResultStr As String
ResultStr = ""
M = Split("1,2,0,1,2,1,2,2,2,1,1,0,2,1,1", ",")
For i = 0 To 14
Re_RND:
For j = 1 To 4
U(j) = Int(Rnd * 10)
L(4 * i + j) = U(j)
Next j
If M(i) = "1" Then
If U(1) + U(2) > U(3) + U(4) Then
ResultStr = ResultStr & M(i)
Else
GoTo Re_RND
End If
ElseIf M(i) = "2" Then
If U(1) + U(2) < U(3) + U(4) Then
ResultStr = ResultStr & M(i)
Else
GoTo Re_RND
End If
ElseIf M(i) = "0" Then
If U(1) + U(2) = U(3) + U(4) Then
ResultStr = ResultStr & M(i)
Else
GoTo Re_RND
End If
End If
Next i
Debug.Print ResultStr
For i = 0 To 14
Debug.Print L(i * 4 + 1), L(i * 4 + 2), L(i * 4 + 3), L(i * 4 + 4), M(i)
Next i
Dim M() As String, ResultStr As String
ResultStr = ""
M = Split("1,2,0,1,2,1,2,2,2,1,1,0,2,1,1", ",")
For i = 0 To 14
Re_RND:
For j = 1 To 4
U(j) = Int(Rnd * 10)
L(4 * i + j) = U(j)
Next j
If M(i) = "1" Then
If IIf((U(1) + U(2) >= 10), U(1) + U(2) - 10, U(1) + U(2)) > IIf((U(3) + U(4) >= 10), U(3) + U(4) - 10, U(3) + U(4)) Then
ResultStr = ResultStr & M(i)
Else
GoTo Re_RND
End If
ElseIf M(i) = "2" Then
If IIf((U(1) + U(2) >= 10), U(1) + U(2) - 10, U(1) + U(2)) < IIf((U(3) + U(4) >= 10), U(3) + U(4) - 10, U(3) + U(4)) Then
ResultStr = ResultStr & M(i)
Else
GoTo Re_RND
End If
ElseIf M(i) = "0" Then
If IIf((U(1) + U(2) >= 10), U(1) + U(2) - 10, U(1) + U(2)) = IIf((U(3) + U(4) >= 10), U(3) + U(4) - 10, U(3) + U(4)) Then
ResultStr = ResultStr & M(i)
Else
GoTo Re_RND
End If
End If
Next i
Debug.Print ResultStr
For i = 0 To 14
Debug.Print L(i * 4 + 1), L(i * 4 + 2), L(i * 4 + 3), L(i * 4 + 4), M(i)
Next i
还不如果大家把基础打好 以后一定能有机会去好的软家公司 just a idea
怎么样,还好吗?你的MSN上还有我吗???
呵呵,怎么还是一个三角呀??这段时间去干什么了?
俺用VB语言在脑中把问题叙述了一遍,想完收工!
Time<10ms
s=mid(sss,i,1)do while true
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
d = Int(Rnd * 10)loopend for
rst=""
for i=1 to len(sss)
s=mid(sss,i,1) do while true
a = Int(Rnd * 10)
b = Int(Rnd * 10)
c = Int(Rnd * 10)
d = Int(Rnd * 10)
if v(a,b,a,d)=s then exit do
loop
rst=rst+a+b+c+d
nextfunction v(a as int,b as int,c as int,d as int) as int
if a+b>c+d then
v=1
elseif a+b<c+d then
v=2
else
v=0
end if
end function语法可能有不错,算法应该没问题
a=(a+b) mod 10
c=(c+d) mod 10
if a>c then
v=1
elseif a<c then
v=2
else
v=0
end if
end function
Dim a(1 To 4) As Long, s As String
s = "120121222110211"
Dim i As Integer, j As Integer
For i = 1 To 15
Dim flag As Integer
flag = CInt(Mid$(s, i, 1))
MakeNum:
For j = 1 To 4
Randomize
a(j) = Rnd * 10
Next j
Select Case flag
Case 0
If (a(1) + a(2)) = (a(3) + a(4)) Then
Debug.Print a(1) & "|" & a(2) & "|" & a(3) & "|" & a(4) & vbCrLf
Else
GoTo MakeNum
End If
Case 1
If (a(1) + a(2)) > (a(3) + a(4)) Then
Debug.Print a(1) & "|" & a(2) & "|" & a(3) & "|" & a(4) & vbCrLf
Else
GoTo MakeNum
End If
Case 2
If (a(1) + a(2)) < (a(3) + a(4)) Then
Debug.Print a(1) & "|" & a(2) & "|" & a(3) & "|" & a(4) & vbCrLf
Else
GoTo MakeNum
End If
End Select
Next i
End Sub
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
运行结果:
9|8|6|108|2|4|70|6|1|57|5|4|36|4|1|1010|9|0|78|3|9|52|1|9|30|0|8|56|10|7|87|9|8|45|8|6|75|0|6|28|6|8|07|7|5|5
-------------------------------------------
也没有人叫我去微软上班啊,呵呵,消遣一下
sub print()
dim a(15)
dim one(4)
str1 = "120121222110211"
response.write str1 & "<br>"
For i = 1 To 15
a(i) = mid(str1,i,1)
Next
for i=1 to 15 if a(i)="1" then
do
for j=1 to 4
one(j)=int(rnd()*10)
next
if one(1)>0 then
if one(1)+one(2)>one(3)+one(4) then
response.write i&" "&a(i)&" "&one(1)&one(2)&one(3)&one(4) &"<br>"
exit do
end if
end if
loop
end if
if a(i)="2" then
do
for j=1 to 4
one(j)=int(rnd()*10)
next
if one(1)>0 then
if one(1)+one(2)<one(3)+one(4) then
response.write i&" "&a(i)&" "&one(1)&one(2)&one(3)&one(4) &"<br>"
exit do
end if
end if
loop
end if
if a(i)="0" then
do
for j=1 to 4
one(j)=int(rnd()*10)
next
if one(1)>0 then
if one(1)+one(2)=one(3)+one(4) then
response.write i&" "&a(i)&" "&one(1)&one(2)&one(3)&one(4) &"<br>"
exit do
end if
end if
loop
end if
nextend subcall print()
%>
======================================================120121222110211
1 1 7552
2 2 8093
3 0 6491
4 1 9631
5 2 4291
6 1 6793
7 2 4585
8 2 4683
9 2 3215
10 1 6718
11 1 2900
12 0 2332
13 2 5159
14 1 5964
15 1 6984
def mk4nums(r):
while(True):
a,b,c,d = random.randrange(1,9),random.randrange(1,9),random.randrange(1,9),random.randrange(1,9)
if ((r == 0 and (a + b) == (c + d)) or ((r == 1) and ( a+ b) < (c + d)) or ((r ==2 ) and (a + b) > (c + d))):
return [a,b,c,d]
#start here
res = []
for c in "120121222110211":
res.append(mk4nums(int(c)))
print res---------------------------------------------------------------
[[2, 6, 6, 5], [5, 4, 2, 4], [4, 8, 4, 8], [3, 6, 8, 7], [7, 3, 3, 3], [5, 4, 8, 4], [3, 8, 5, 4], [8, 3, 4, 4], [5, 6, 3, 7], [4, 1, 5, 8], [1, 4, 3, 3], [4, 3, 6, 1], [4, 7, 2, 1], [4, 1, 6, 8], [2, 2, 4, 2]]
CSDN的垃圾论坛,把我PYTHON的前导空格干掉了.
Dim ShiWu As String
Dim a, b, c, d, e, h, j As Integer
Dim g As String
g = ""
Dim f(1 To 15) As String
ShiWu = "120121222110211"For i = 1 To 15
a = Int((9 - 0 + 1) * Rnd + lowerbound)
b = Int((9 - 0 + 1) * Rnd + lowerbound)
c = Int((9 - 0 + 1) * Rnd + lowerbound)
d = Int((9 - 0 + 1) * Rnd + lowerbound)
e = 0j = Val(Mid("120121222110211", i, 1))
Select Case j
Case 1
While 1 > e
If a + b > c + d Then
e = 2
f(i) = Trim(Str(a)) & Trim(Str(b)) & Trim(Str(c)) & Trim(Str(d))
Else
a = Int((9 - 0 + 1) * Rnd + lowerbound)
b = Int((9 - 0 + 1) * Rnd + lowerbound)
c = Int((9 - 0 + 1) * Rnd + lowerbound)
d = Int((9 - 0 + 1) * Rnd + lowerbound)
End If
Wend
Case 2
While 1 > e
If a + b < c + d Then
e = 2
f(i) = Trim(Str(a)) & Trim(Str(b)) & Trim(Str(c)) & Trim(Str(d))
Else
a = Int((9 - 0 + 1) * Rnd + lowerbound)
b = Int((9 - 0 + 1) * Rnd + lowerbound)
c = Int((9 - 0 + 1) * Rnd + lowerbound)
d = Int((9 - 0 + 1) * Rnd + lowerbound)
End If
Wend
Case 0
While 1 > e
If a + b = c + d Then
e = 2
f(i) = Trim(Str(a)) & Trim(Str(b)) & Trim(Str(c)) & Trim(Str(d))
Else
a = Int((9 - 0 + 1) * Rnd + lowerbound)
b = Int((9 - 0 + 1) * Rnd + lowerbound)
c = Int((9 - 0 + 1) * Rnd + lowerbound)
d = Int((9 - 0 + 1) * Rnd + lowerbound)
End If
Wend
End Select
Next i
For h = 1 To 15
g = g & f(h)
Next h
Me.Combo1.AddItem g
MsgBox g
End Sub
Dim b As Integer, f As Integer
Dim c As Integer
Dim d As Integer
Dim str1 As String
Dim arr(15) As Integer
Private Sub Form_Load()
Randomize
str1 = "120121222110211"
For i = 0 To 14
arr(i) = Val(Right(Left(str1, i + 1), 1))
Next
For i = 0 To 14
num: a = Int(Rnd() * 9)
b = Int(Rnd() * 9)
c = Int(Rnd() * 9)
d = Int(Rnd() * 9)
e = a + b
f = c + d
Select Case arr(i)
Case 0
If e <> f Then
GoTo num
Else
Text1.Text = Text1.Text & Chr(13) & Chr(10) & i + 1 & " " & a & b & c & d & " "
End If
Case 1
If e > f Then
Text1.Text = Text1.Text & Chr(13) & Chr(10) & i + 1 & " " & a & b & c & d & " "
Else
GoTo num
End If
Case 2
If e < f Then
Text1.Text = Text1.Text & Chr(13) & Chr(10) & i + 1 & " " & a & b & c & d & " "
Else
GoTo num
End If
End Select
Next
End Sub结果:
1 6402
2 1053
3 3241
4 5611
5 2028
6 1523
7 5373
8 2746
9 7365
10 1606
11 7243
12 5234
13 1680
14 5663
15 4820
Dim a As Integer, e As Integer
Dim b As Integer, f As Integer
Dim c As Integer
Dim d As Integer
Dim str1 As String
Dim arr(15) As Integer
Private Sub Form_Load()
Randomize
str1 = "120121222110211"
For i = 0 To 14
arr(i) = Val(Right(Left(str1, i + 1), 1))
Next
For i = 0 To 14
num: a = Int(Rnd() * 9)
b = Int(Rnd() * 9)
c = Int(Rnd() * 9)
d = Int(Rnd() * 9)
e = a + b
f = c + d
If e > 10 Then e = e - 10
If f > 10 Then f = f - 10
Select Case arr(i)
Case 0
If e <> f Then
GoTo num
Else
Text1.Text = Text1.Text & Chr(13) & Chr(10) & i + 1 & " " & arr(i) & " " & a & b & c & d & " "
End If
Case 1
If e > f Then
Text1.Text = Text1.Text & Chr(13) & Chr(10) & i + 1 & " " & arr(i) & " " & a & b & c & d & " "
Else
GoTo num
End If
Case 2
If e < f Then
Text1.Text = Text1.Text & Chr(13) & Chr(10) & i + 1 & " " & arr(i) & " " & a & b & c & d & " "
Else
GoTo num
End If
End Select
Next
End Sub
运行结果:
1 1 8865
2 2 1272
3 0 6006
4 1 0585
5 2 4053
6 1 2834
7 2 0373
8 2 1361
9 2 6714
10 1 3684
11 1 0430
12 0 6712
13 2 7860
14 1 2706
15 1 4474
比尔的软件能力是不错,可并没有达到天才的地步,这样胡吹就出了格了。比尔的能力在经营,诀窍在运气。
不过对于现在的软件人员来说,以前那种编程要求是很少有人能达到的了。
举个简单的例子,用一个Picture控件来编写一个Text控件,有几个人能做到?
如果你解答该题只花了10-30分钟,那你也应该算得上一个精良的VB程序员
如果你解答该题花了30分钟-2小时,那你VB理论学得蛮精通
如果你解答该题花了2小时-1天时间,那你还得加油啊
如果你解答该题花了1天-5天,那你肯定是个新手
如果你根本不会解答该题,那你的潜力将无法估量!
--------------------------------------------------
这个是你自己吹的吧,很多学生都能在<10分钟内写出这道题。