战平printf函数做了一个长方形,由内部框架 [英] Draw a rectangle made with printf function, consisted of inner frames

查看:187
本文介绍了战平printf函数做了一个长方形,由内部框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想这几个小时,但不能想出一个办法做到这一点。
我们给予在学校分配以获取高度和宽度2输入(假设他们之间2-50)
并以这种方式创建一个矩形:
在矩形框会被造出来的字母a,
内部矩形框会被造出来的字母B的,
内部矩形框架的内矩形框会被造出来的字母C,
等等...
如:

I've been trying this for hours but couldn't figure out a way to do it. We were given an assignment in school to get 2 inputs for Height and Width(assuming they're between 2-50), and create a rectangle in this way: the rectangle frame will be made out of the letter a, the inner rectangle frame will be made out of the letter b, the inner rectangle frame of the inner rectangle frame will be made out of the letter c, and so on... for instance:

10X7:
aaaaaaaaaa
abbbbbbbba
abccccccba
abcddddcba
abccccccba
abbbbbbbba
aaaaaaaaaa

我试图与工作为的高度和宽度循环
我正在画矩阵草案,看看如何改变信与ASCII值跳跃,
但我无法找出一种算法。
帮助将是非常美联社preciated。

I was trying working with "for" loops for height and width and I was drawing matrix as draft to see how to change the letter jumping with ASCII values, but I couldn't figure out an algorithm. help would be very appreciated.

推荐答案

由于您没有公布code,我也只是口头描述一个可能的算法。

As you have not posted code, I will also just verbally describe a possible algorithm.

您将需要两个嵌入式for循环。外环线线路(X)内的线(Y),内环路的字符。双方应从零运行XMAX和YMAX,这是在命令行中减去一个指定的号码。

You'll need two embedded for loops. Outside loop for lines (y), inside loop for characters within line (x). Both shall run from zero to xmax and ymax, which are the numbers specified on the command line minus one.

里面的内循环的身体,你必须找到框架。这取决于到边缘的距离。但是哪条边?最近的一个。所以该距离(X,Y,XMAX-X,YMAX-Y)的最小值。

Inside the body of the inner loop you have to find the frame. It depends on the distance to the edge. But which edge? The closest one. So this distance is the minimum of (x, y, xmax-x, ymax-y).

然后打印'A'+距离。此外,在每行后,打印一个换行符。

Then you print 'a' + distance. Additionally, after each line, you print a linefeed.

这篇关于战平printf函数做了一个长方形,由内部框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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