2012-03-12 71 views
0

打印垂直直方圖。編寫一個程序,要求用戶輸入一個整數列表,然後垂直打印一個直方圖到屏幕上。整數以空格分隔的字符串形式輸入。如何使用數字編寫垂直直方圖?

這是我的輸出應該是這樣的:

Please enter a string of integers separated by spaces: 1 3 6 5 2 7 

****** 
***** 
*** * 
    ** * 
    ** * 
    * * 
    * 

我無法弄清楚如何使直方圖垂直...幫助我嗎?

+0

你使用哪種語言?你試過什麼了? – 2012-03-12 01:48:58

回答

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 

現在,您的任務是將此僞代碼轉換爲您的教師選擇的語言。