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

59 строки
1.5 KiB
C++

#include "text.h"
#include <iostream>
using namespace std;
void show_histogram_text(const vector<size_t>& bins) {
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
auto bin_count = bins.size();
size_t max_count = 0;
for (size_t i = 0; i < bin_count; i++) {
size_t Count = bins[i];
if (max_count < Count) {
max_count = Count;
}
}
if (max_count <= MAX_ASTERISK) {
for (size_t i = 0; i < bin_count; i++) {
size_t Count = bins[i];
for (size_t j = 0; j < max_count - Count; j++){
cout << " ";
}
for (size_t j = 0; j < Count; j++){
cout << "*";
}
cout << "|";
if (Count < 100) {
cout << " ";
}
if (Count < 10) {
cout << " ";
}
cout << Count << "\n";
}
}
else {
for (size_t i = 0; i < bin_count; i++) {
size_t Count = bins[i];
size_t height = 76 * (static_cast<double>(Count) / max_count);
for (size_t j = 0; j < max_count - height; j++){
cout << " ";
}
for (size_t j = 0; j < height; j++){
cout << "*";
}
cout << "|";
if (Count < 100) {
cout << " ";
}
if (Count < 10) {
cout << " ";
}
cout << Count << "\n";
}
}
}