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

31 строка
687 B
C++

#include <iostream>
#include <vector>
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 maxCount = bins[0];
for (auto bin : bins) {
if (maxCount < bin) {
maxCount = bin;
}
}
for (auto bin : bins) {
if (bin < 100)
{
cout << " ";
}
if (bin < 10)
{
cout << " ";
}
size_t height = maxCount < MAX_ASTERISK ? bin : MAX_ASTERISK * (static_cast<double>(bin) / maxCount);
cout << bin << "|" << string(height, '*');
cout << "\n";
}
}