如何使某个角色成为一个形状? [英] How do I make a certain character a shape?

查看:53
本文介绍了如何使某个角色成为一个形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建输入字符和宽度的形状? (例如,如果我想在最宽的点使用@ @@mbmbols创建一个钻石?



我尝试了什么:



不知道如何启动这个程序。

解决方案

我们不做你的功课:它是为一个原因。它就是为了让你思考你被告知的事情,并试着去了解它。它也在那里,以便你的导师可以找出你身体虚弱的地方,并把更多的注意力放在补救行动上。



亲自尝试一下,你可能会发现它并不像你想象的那么困难!

从破坏任务开始:它是两半,一个是打印增加的字符:

 @ 
@@@
@@@@@

打印递减字符:

 @@@ 
@

所以首先想一想并分别做每个一半。

首先让上半部分工作,然后考虑底部。顶部很漂亮easy:它是一个打印行的循环,然后是一个循环来打印字符。在第一行,你需要打印x空格和y字符,其中

 2x + y = n 

和< pre lang =text> y = 2l + 1

其中 l 是行号,基于零:

 @ x = 2,y = 1,l = 0,n = 5 
@@@ x = 1,y = 3,l = 1,n = 5
@@@@@ x = 0,y = 5,l = 2,n = 5

从那开始,看看你能走多远。



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!


How do I create a shape with an inputted character and width? (ex if I want to create a diamond using @ with 31 @symbols at the widest point?

What I have tried:

not sure how to start this program.

解决方案

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!
Start by breaking the task down: it's two halves, one to print the "increasing" chars:

  @
 @@@
@@@@@

And one to print the "decreasing" chars:

@@@
 @

So start by thinking of it that way, and do each "half" separately.
Get the "top half" working first, then think about the bottom. The top is pretty easy: it's a loop to print the lines, then a loop inside that to print the characters. On teh first line, you need to print "x" spaces and "y" characters, where

2x + y = n

And

y = 2l + 1

Where l is the line number, zero based:

  @    x = 2, y = 1, l = 0, n = 5
 @@@   x = 1, y = 3, l = 1, n = 5
@@@@@  x = 0, y = 5, l = 2, n = 5

Start with that, and see how far you can get.

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于如何使某个角色成为一个形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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