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

34 строки
872 B
C++

#include "text.h"
#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 max_count = bins[0];
for (size_t count : bins) {
if (count > max_count)
max_count = count;
}
for (size_t j = 0; j < bins.size(); j++) {
if (bins[j] < 100) cerr << " ";
if (bins[j] < 10) cerr << " ";
cerr << bins[j] << "|";
size_t height = 0;
if (max_count > MAX_ASTERISK) {
height = static_cast<size_t>(
static_cast<double>(bins[j]) / max_count * MAX_ASTERISK
);
}
else {
height = bins[j];
}
for (size_t i = 0; i < height; i++)
cerr << "*";
cerr << endl;
}
}