添加数组 0-99 的中间 20 个值
对于其他人来说,这似乎很容易,但我很难理解它。 我必须将数组 0-99 中间 20 个索引中保存的数字相加 但我无法弄清楚我应该添加哪个索引到哪个索引。 是40-60之间的吗?或者是 22 个值?
This may seem quiete easy to everyone else but I am struggling to comprehend it.
I have to add up the numbers held in the middle 20 indexes of an array 0-99
but I cant work out from what index to what index I should add.
Is it from 40-60? or is that 22 values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你在计算不是从 1 开始的连续整数列表中的内容时遇到困难,那么想象一下从所有这些整数中减去最低的索引,然后加 1。然后你将得到一个从 1 开始的连续整数,所以无论顶部是多少索引将是事物的计数。
因此,在 40-60 的情况下,您可以从所有内容中减去 40,然后加 1,以查看这些索引映射到数字 1 到 21。
为了获得正确答案,可以使用此方法的简单扩展。 0-99 是 100 个值(只需将所有值加一即可看到这一点)。这意味着您需要跳过 40 个值,然后获取接下来的 20 个值。
因此,要计算出您跳过的值,您需要从 0 开始,然后获取 40 个项目。您可以很容易地看到,在向列表添加 1 后,您希望顶级索引为 40(因此您的索引映射到 1-40),这意味着实际索引为 0-39。因此,40 然后开始您的列表,以类似的方式,您可以说,如果 40 是您的第一个索引 (40-39=1),那么您的最后一个索引将为 59(因为 59-39 = 20)。
因此,答案是您正在查看索引 40-59。
我希望这不仅可以帮助您在这里找到答案,还可以帮助您弄清楚如何自己做到这一点。
if you are having trouble counting things in lists of consecutive integers that are not starting at one then just imagine subtract the lowest index from all of them and then add 1. Then you will have a lsit of consecutive integers starting from 1 so whatever the top index is will be the count of the thing.
So in the case of 40-60 you can subtract 40 from everything and add one to see that these indexes map to the numbers 1 to 21.
To get your correct answer a simple extension of this can be used. 0-99 is 100 values (just add one to all of them to see this). That means you need to skip 40 values and then take the next 20.
So to work out the ones you skip you want to start at 0 and then take 40 items. You can easily see that after adding one to the list you want your top index to be 40 (so your indexes map to 1-40) which means the actual indexes are 0-39. So 40 then starts your list and in a similar way you can say that if 40 is your first index (40-39=1) then your last index will be 59 (since 59-39 = 20).
Thus the answer is that you are lookign at indexes 40-59.
I hope this not only helps you get the answer here but helps you work out how to do it on your own.
索引 40 - 索引 59 是你的中间范围;)
index 40 - index 59 is your middle-range ;)