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

39 строки
665 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 ShowHistogrammText(vector<size_t> Bins) {
size_t MaxCount = 0;
for (auto bin : Bins) {
if (MaxCount < bin) {
MaxCount = bin;
}
}
for (auto bin : Bins) {
if (bin < 100) {
cout << " ";
}
if (bin < 10) {
cout << " ";
}
cout << bin << "|";
size_t height = MAX_ASTERISK * (static_cast<double>(bin) / MaxCount);
if (MaxCount <= 76) {
for (int i = 0; i < bin; i++) {
cout << '*';
}
}
else {
for (int i = 0; i < height; i++) {
cout << '*';
}
}
cout << endl;
}
}