You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
532 B
32 lines
532 B
2 years ago
|
! Plot a histogram from a stream of nonzero integers.
|
||
|
|
||
|
let
|
||
|
const mid ~ 40;
|
||
|
var n : Integer;
|
||
|
|
||
|
proc putmany (c : Char, n : Integer) ~
|
||
|
let
|
||
|
var i : Integer
|
||
|
in
|
||
|
begin
|
||
|
i := 0;
|
||
|
while i < n do
|
||
|
begin put (c); i := i + 1 end
|
||
|
end;
|
||
|
|
||
|
proc makenonnegative (var n : Integer) ~
|
||
|
if n < 0 then n := 0 - n else
|
||
|
|
||
|
in
|
||
|
begin
|
||
|
getint (var n); geteol ();
|
||
|
while n \= 0 do
|
||
|
begin
|
||
|
putmany (' ', if n > 0 then mid else mid + n);
|
||
|
makenonnegative (var n);
|
||
|
putmany ('+', n);
|
||
|
puteol ();
|
||
|
getint (var n); geteol ()
|
||
|
end
|
||
|
end
|