Родитель
d6b25e4718
Сommit
ad0b839a13
@ -0,0 +1,38 @@
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH -3 -1;
|
||||
|
||||
void
|
||||
show_histogram_text(const vector<size_t>& bins)
|
||||
{
|
||||
size_t max_count = 0;
|
||||
for (size_t count : bins)
|
||||
{
|
||||
if (count > max_count)
|
||||
{
|
||||
max_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t count :bins){
|
||||
if (count < 10){
|
||||
cout << " " << count <<"|";}
|
||||
else if (count < 100){
|
||||
cout <<" " << count << "|";}
|
||||
if (count <1000){
|
||||
cout << count <<"|";}
|
||||
size_t height;
|
||||
if (max_count <= MAX_ASTERISK){
|
||||
height=count;}
|
||||
else{
|
||||
height = static_cast<size_t>(MAX_ASTERISK*(static_cast<double>(count)/ max_count));}
|
||||
|
||||
for (size_t j = 0; j< height ; j++){
|
||||
cout << "*";}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
Загрузка…
Ссылка в новой задаче