0

我需要帮助来解决以下测试问题(这不是家庭作业或作业),用户可以从控制台输入 1-9 的值,并且程序接受 3 个数字,每行一个数字。如果用户输入以下内容:

  • 3
  • 2
  • 4

输出应该是:

              1
             2 2
            3 3 3
             1
            2 2
               1
              2 2
             3 3 3
            4 4 4 4

我对树没有任何经验,所以请告诉我那是什么树,我可以从哪里开始完成上述程序(我需要一些提示和建议,这将有助于我制作这个程序)

提前致谢。

4

2 回答 2

1

No tree data structure is required. The general features of your program would be the following:

  • Read the three inputs
  • For each input n, use a for loop from 1 to n to print n lines using n as the output values
  • (The bit harder part:) On each line, you will also need to generate the required spacing. This will involve a calculation on your part based on n and the max value of n. Since n is a single digit, you won't have to take into account n taking up more characters once it's >= 10.
于 2013-01-31T12:26:55.710 回答
0

定义一个将保存数字的二维字符数组。从顶部中间开始。使用递归。

于 2013-01-31T12:23:29.550 回答