俺昨天才来逛过,偶然发现这题,产生了兴趣,工余试了一下,因VBA不懂,太烦琐了,请大侠指点。
Private Sub CommandButton1_Click() t = Timer i = 1 j = 1 For A = 1 To 9 '万位数字
For B = 0 To 9 '千位数字
For C = 0 To 9 '百位数字
For D = 0 To 9 '十位数字
For E = 0 To 9 '个位数字
H = A + B + C + D + E '五位数的票面数字和 Q = 10000 * A + 1000 * B + 100 * C + 10 * D + E '设第一张票的号码 P = Q + 1 '因票的号相连,故取第一张票的号+1 X = Int(Q / 10000) + Int(Q / 1000) - Int(Q / 10000) * 10 + Int(Q / 100) - Int(Q / 1000) * 10 + Int(Q / 10) - Int(Q / 100) * 10 + Q - Int(Q / 10) * 10 '票的号码数字相加值 Y = Int(P / 10000) + Int(P / 1000) - Int(P / 10000) * 10 + Int(P / 100) - Int(P / 1000) * 10 + Int(P / 10) - Int(P / 100) * 10 + P - Int(P / 10) * 10 '票的号码数字相加值
If H = 35 And X + Y = 62 Then '若回答是 =35 的情况 Sheet2.Cells(i + 2, 2) = i '列明第几种情况 Sheet2.Cells(i + 2, 3) = Q '列出第一张票的号码 Sheet2.Cells(i + 2, 4) = P '列出第二张票的号码 Sheet2.Cells(2, 3) = "第一张票号:" Sheet2.Cells(2, 4) = "第二张票号:" Sheet2.Cells(1, 2) = "其中一个票号=35时,两张票的号码分别如下:" Sheet2.Cells(1, 5) = "共有:" & i & "种情况。" '统计 =35 的情况数量 i = i + 1
ElseIf X + Y = 62 Then ' 若回答不是 =35 的情况 Sheet3.Cells(j + 2, 2) = j Sheet3.Cells(j + 2, 3) = P Sheet3.Cells(j + 2, 4) = Q Sheet3.Cells(2, 3) = "第一张票号:" Sheet3.Cells(2, 4) = "第二张票号:" Sheet3.Cells(1, 2) = "其中一个票号≠35时,两张票的号码分别如下:" Sheet3.Cells(1, 5) = "共有:" & j & "种情况。" j = j + 1 End If
Next Next Next Next Next Sheet1.Cells(2, 3) = Timer - t & "s" '在第一张表中显示计算用时 Sheet2.Cells(2, 5) = Timer - t & "s" '在第二张表中显示计算用时 Sheet3.Cells(2, 5) = Timer - t & "s" '在第三张表中显示计算用时
End Sub |