有越来越多的行阵 [英] Increasing Array with Rows

查看:80
本文介绍了有越来越多的行阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个数字数组:

int[] that = new [] {1, 2, 3, 2, 4, 8, 9, 7};

我想显示他们,这样被越来越多的数字有自己的路线。
例如,结果将是:

I'm trying to display them so that the numbers that are increasing have their own line. For example the result would be:

1 2 3

2 4 8 9

7

我能够用做的第一排,

for (int i = 1; i < that.Length; i++) 
{
    if (that[i-1] < that[i]) 
    {
        Console.Write(that[i-1] + " ");
    }
}

关键是这个工程的第一排,因为1-3在增加,但之后停止。
我不完全知道如何继续下去,以便2 4 8 9,那么7编写的。

The thing is this works for the first row because 1-3 are increasing but stops after that. I'm not exactly sure how to continue so that 2 4 8 9, then 7 are written.

推荐答案

我有一种感觉,这是家庭作业,所以我要去实际编码留给你。但这里是如何做到这一点用通俗易懂的语言:

I have a feeling this is homework so I'm going to leave the actual coding to you. But here's how to do it in plain language:


  1. 有我们存储previous值的变量。让我们把它的属性oldValue,并以零开始(如果你只数组中使用的正数)。

  2. 通过数组一个项目去一次。

  3. 检查,看看是否能数比属性oldValue大。

  4. 如果FALSE,打印新行字符。 \\ n,在C#。

  5. 打印的数量,并属性oldValue等于这个数字。

  6. 除非你的数字是完成获取下一个号码,转到步骤3。

这篇关于有越来越多的行阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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