打印垂直直方图。编写一个程序,要求用户输入整数列表,然后在屏幕上垂直打印直方图。整数输入为以空格分隔的字符串。
这是我的输出应该是这样的:
Please enter a string of integers separated by spaces: 1 3 6 5 2 7
******
*****
*** *
** *
** *
* *
*
我无法弄清楚如何使直方图垂直...帮帮我?
答案 0 :(得分:1)
整个程序应如下所示:
read the numbers into a list.
print the histogram of the list.
打印列表的直方图:
find the maximum of the numbers.
for each number starting with the maximum, going down to 1:
print the corresponding line of the histogram.
打印直方图的行x
:
for each of the numbers from the list:
if x is at least the number:
print " *"
otherwise:
print " "
print a linebreak
现在您的任务是将此伪代码转换为教师选择的语言。
答案 1 :(得分:0)
垂直文本直方图:
|
| |
|| |
|| |
||| |
|||||
||||||