作业帮 > 综合 > 作业

假设“M-N"表示除以M的余数是N (N

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/13 21:31:56
假设“M-N"表示除以M的余数是N (N在EXCEL的A1中有数据:“6-3,9-0,10-1,”(表示6-3,9-0,10-1在1到40内的两两交集的并集).现在要将A1中的数据转为整数输出.求VBA(EXCEL自定义函数)
上例操作过程为:6-3(在1到40内)即为“3,9,15,21,27,33,39, 9-0(在1到40内)即为“9,18,27,36,” 10-1(在1到40内)即为:1,11,21,31,” 6-3与9-0的交集为:9,27, 6-3与10-1 的交集为:21 9-0与10-1的交集没有.现在输出“9,21,27,”
假设“M-N
Function fc(x)
Dim dic As Object, a, b%(40), i%, j%, f, aa
For j = 1 To 40: b(j) = 0: Next j
x = Replace(x, ",", ",")
x = Replace(x, "-,", "-")
a = Split(x, ",")
For i = 0 To UBound(a) - 1
aa = Split(a(i), "-")
For j = 1 To 40
If j Mod Val(aa(0)) = Val(aa(1)) Then b(j) = b(j) + 1
Next j
Next i
f = ""
For j = 1 To 40
If b(j) > 1 Then f = f & j & ","
Next j
fc = f
End Function