4位数字的组合,其单个数字总和为5

编程入门 行业动态 更新时间:2024-10-14 22:14:28
本文介绍了4位数字的组合,其单个数字总和为5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在工作的计分卡上,该列具有代表4种可能结果的列,例如:

I'm working on a scorecard at work which has columns representing 4 possible outcomes, for example:

  • 成功,
  • 失败,
  • 非凡,
  • 其他
  • 每个工作人员每月都会根据这些评级进行5次评估.因此, 1个人可能会成功 3个成功, 2个例外, 0个不成功, 0个其他 >.

    Each staff member is assessed 5 times in the month against those ratings. So 1 person might have 3 successful, 2 exceptional, 0 unsuccessful, 0 other.

    因此,每个结果的最大实例数为5,但实例的总和不能超过5.

    So the max instances of each outcome is 5 but the total sum of instances can't be more than 5.

    我可以尝试输入所有组合(并弄错)-是否有人知道的功能/公式/VBA会为我列出所有可能的结果组合?

    I could try to type out all the combinations (and get them wrong) - is there any function/formula/VBA that anyone knows of that will list out all of the possible combinations of outcomes for me?

    e.g. 5000,4100,4010,4001,3200,3020,3002,3110,3011, etc...

    推荐答案

    由于您的数字范围可以从0005到5000,因此您可以编写一个简单的循环来测试每个数字以查看数字是否总计:

    Since your numbers can range from 0005 to 5000, you could just write a simple loop that tests each number to see if the digits total 5:

    Sub GetPermutations() Dim i As Long For i = 5 To 5000 If SumDigits(i) = 5 Then Debug.Print Format$(i, "0000") Next End Sub Function SumDigits(s As Variant) As Long Dim i As Long For i = 1 To Len(s) SumDigits = SumDigits + CLng(Mid$(s, i, 1)) Next End Function

    或者:

    Dim w As Long, x As Long, y As Long, z As Long For w = 0 To 5 For x = 0 To 5 For y = 0 To 5 For z = 0 To 5 If w + x + y + z = 5 Then Debug.Print w & x & y & z Next Next Next Next

    更多推荐

    4位数字的组合,其单个数字总和为5

    本文发布于:2023-11-29 16:04:10,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1646884.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:数字   组合   总和

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!