ok... so I have been working on a stupid program that takes in characters one at a time and then counts then and then prints out how many characters there are and a graph.. but I don't know how to make my graph vertical... can any one /prog/ help a fool like me?
source:
#include <stdio.h>
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
int cols;
int max = 80;
int c;
int y;
int k;
int count[26];
for (int x = 0; x < 26; x++)
count[x] = 0;
while (! cin.eof())
{
if( isalpha ( c = tolower( cin.get() ) ) )
count [ c - 'a']++ ; // for everytime a certain value appears add 1 to that values number and when it shows up again add another 1 = 2
}
for (int i = 0; i < 26; i++)
printf("[%c] = %d\n" , i+'a' , count[i]);
for (int x=0; x<26; x++)
{
if (count[x] > 1)
{
cols = max * count[x] / count[25] ;
for (int y=0; y < cols; y++)
cout.put('-') ;
cout.put ('\n');
}
}
return 0;
}
Name:
pieisgood2007-08-16 11:20 ID:uwvkYoYJ
alright, thanks guys that helped a lot. I am starting to warm up to /prog/ it's like /g/ sage first, help later.
#include <stdio.h>
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
int cols;
int max = 30;
int c;
int y;
int count[26];
for (int x = 0; x < 26; x++)
count[x] = 0;
while (! cin.eof())
{
if( isalpha ( c = tolower( cin.get() ) ) )
count [ c - 'a']++ ; // for everytime a certain value appears add 1 to that values number and when it shows up again add another 1 = 2
}
for (int i = 0; i < 26; i++)
printf("[%c] = %d\n" , i+'a' , count[i]);
cols = count[25] / max;
for (int y = max; y > 0; y--)
{
for (int x=0; x < 26; x++)
{
if (count[x] / cols >= y)
cout.put('^') ;
else
cout.put (' ');
}
cout.put('\n');
}
return 0;
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
Name:
Anonymous2007-08-16 12:31 ID:cNnPpPGu
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
Name:
Anonymous2007-08-16 12:31 ID:cNnPpPGu
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))