查找二维数组的最多3个元素 [英] Finding max 3 elements of a 2 dimensional array

查看:84
本文介绍了查找二维数组的最多3个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试发展我的解决问题"的能力.我花了太多时间.但是,我找不到找到二维数组中最多3个元素的解决方案.例如,

1 12 4
7 9 15
2 2 2

是数组.我想获得12,15和9作为输出.

Hello everyone,

I am trying to develop my "problem solving" ability. I spent too much time. However, I cant find a solution finding the max 3 elements of a 2 dimensional array. For example,

1 12 4
7 9 15
2 2 2

is the array. I want to get 12,15 and 9 as output.

推荐答案

使用嵌套循环遍历2d数组,然后您可以问,
如果实际值大于第一个最大值,则将第二个最大值保存在第三个位置,将当前的第一个最大值保存在secon位置,然后将实际值保存在第一个位置.然后检查下一个号码.
如果实际值小于第一个最大值,但大于第二个,则直接从pos 2开始相同
如果实际值小于第二个最大值且大于第三个,则将实际值保存在第3个位置,然后检查.

编写代码应该是您的工作.如果您有问题,可以提出疑问,但请向我们显示您的尝试.
如果您想问与此有关的其他事情,请使用小部件改善问题"并编辑消息,不要添加新的问题或新的解决方案.如果您想直接与我交谈,请使用有问题或评论吗?"
Use a nested loop to go through the 2d array then you can ask,
if actual value is bigger than the first maximum, save the second maximum in the third position and the current first maximum in the secon position, then save actual value in first position. Then check the next number.
if actual value is smaller than first max, but bigger than second, the same starting directly in pos 2
if actual value is smaller than second max and bigger than third, then save actual value in 3rd position and check next.

To code that should be your work. If you have problems, then you can ask, but show us what you are trying.
If you want to ask other thing related to this, then please use the widget "improve questio" and edit the message, don''t add a new question or a new solution. If you want to directly speak with me, then use "have a question or comment?"


Sub Find_max(ByVal a As Integer(,))
    Dim i, j As Integer
    Dim newArray As Integer() = New Integer(9) {}

    For i = 0 To 2
        For j = 0 To 2
            newArray(3 * i + j) = a(i, j)
        Next
    Next

    Array.Sort(newArray)

    For index2 = 9 To 7 Step -1
        Console.Write(newArray(index2) & vbTab)
    Next


通过提出此类问题并获得答案,可能会严重损害您的解决问题"技能.您想训练哪些技能:您自己的还是专家的?''!

自己做;这是唯一的方法.如果对您而言不明显,那么您的前景将非常糟糕.

—SA
By asking such questions and getting answers, you can seriously damage your "problem solving" skills. Which skills do you want to train: your own, or the experts''?!

Do it by yourself; this is the only way. If it''s not apparent to you, your prospects are very poor.

—SA


这篇关于查找二维数组的最多3个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆