Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

39 строки
919 B
C++

#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;
}
}