两个数字的匹配问题
vb吧
全部回复
仅看楼主
level 3
求助
怎么判断两个三位数是否有三个数字相同(两数不相等)
还有是否只有一个数字相同
2022年10月08日 10点10分 1
level 11
Option Explicit
Private Sub Command1_Click()
Dim x As Integer
Dim y As Integer
Dim xx(1 To 3) As Integer
Dim yy(1 To 3) As Integer
Dim i As Integer
Dim j As Integer
Dim m As Integer
Dim n As Integer
Do
x = Val(InputBox("请输入第一个三位数"))
Loop Until x >= 100 And x <= 999
Do
y = Val(InputBox("请输入第二个三位数,不等于" & x))
Loop Until y >= 100 And y <= 999 And y <> x
xx(3) = x Mod 10
xx(2) = x \ 10 Mod 10
xx(1) = x \ 100
yy(3) = y Mod 10
yy(2) = y \ 10 Mod 10
yy(1) = y \ 100
Do
m = n
Do
For i = 1 To 3
If xx(i) >= 0 Then
For j = 1 To 3
If xx(i) = yy(j) Then
n = n + 1
xx(i) = -1
yy(j) = -1
Exit Do
End If
Next j
End If
Next i
Exit Do
Loop
Loop Until n = m
Print x & "和" & y & "有" & n & "个数字相同"
End Sub
2022年10月08日 15点10分 2
谢谢
2022年10月09日 07点10分
1