2012-03-12 2 views
0

수직 막대 그래프 인쇄. 사용자에게 정수 목록을 입력하고 화면에 수직으로 막대 그래프를 인쇄하도록 요청하는 프로그램을 작성하십시오. 정수는 공백으로 구분 된 문자열로 입력됩니다.숫자를 사용하여 세로 막대 그래프를 작성하려면 어떻게합니까?

이 내 출력처럼 보이도록되어있는 것이다 :

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

****** 
***** 
*** * 
    ** * 
    ** * 
    * * 
    * 
내가 히스토그램 수직 만드는 방법을 알아낼 수 없습니다

... 도와주세요?

+0

어떤 언어를 사용하고 있습니까? 지금까지 뭐 해봤 어? –

답변

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 

이제이 의사 코드를 강사가 선택한 언어로 변환하십시오.

관련 문제