我如何打印这种模式?有什么建议!!! [英] How I do print this pattern? Any suggestions!!!

查看:92
本文介绍了我如何打印这种模式?有什么建议!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印以下图案?有什么建议!



AAABAAA

AABBBAA

ABBBBBA

BBBBBBB

How to print following pattern?? any suggestions!

A A A B A A A
A A B B B A A
A B B B B B A
B B B B B B B

推荐答案

我会开始使用两个循环编写所有'A' 。这应该是微不足道的。

然后,根据循环的索引(比如 row )找到正确的 if 语句打印'A''B '





[update]

例如,请参阅 C - if ... else语句 [ ^ ]。不过我建议你读一本关于 C 编程语言的好书。

[/ update]
I would start writing all 'A's using two for loops. That should be trivial.
Then, based on the indices of the loops (say row, column) find the right if statement for printing either 'A' or 'B'.


[update]
See, for instance, C - if...else statement[^]. However I suggest you reading a good book on the C programming language.
[/update]


我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



但这非常简单。看看它:每行需要打印两个B,直到你在该行上没有打印Aa。并且每行上的A的数量对于前缀变少一个,对于后缀每次少一个。



因此有一个循环的行,并调用一个函数来打印行 - 传递要打印的字符总数和B的数量。让它返回打印的A的数量。在循环中,检查返回值,如果它为零,则退出循环。



完成。
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

But this is pretty trivial. Look at it: each row you need to print two more "B"s until you have printed no "A"a at all on that row. And the number of "A"s on each row becomes one less for the prefix and one less for the suffix each time.

So have a loop for the rows, and call a function to print the row - passing it the total number of characters to print, and the number of "B"s. Have it return the number of "A"s it printed. In the loop, check the return value, and if it's zero, exit the loop.

Done.


你的内容是每行要打印的As和B的数量的公式,具体取决于行的当前索引,或者是开始和结束打印Bs而不是As的列号的公式。要想出一个主意,请记下每一行所需的数字,然后找到这些数字背后的公式。
What you ned are formulas for either the number of As and Bs to print for each row, depending on the current index of the row, or formulas for the column numbers where you start and end printing Bs instead of As. To get an idea, write down the required numbers for each row, then find the formula behind these numbers.


这篇关于我如何打印这种模式?有什么建议!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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