Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
41 строка
1.0 KiB
C++
41 строка
1.0 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 - 4;
|
|
|
|
size_t max_bin_count = 0;
|
|
for (size_t bin : bins) {
|
|
if (bin > max_bin_count) {
|
|
max_bin_count = bin;
|
|
}
|
|
}
|
|
|
|
if (max_bin_count <= MAX_ASTERISK) {
|
|
for (size_t bin : bins) {
|
|
if (bin < 10) cout << " ";
|
|
cout << " " << bin << "|";
|
|
for (size_t j = 0; j < bin; j++) {
|
|
cout << "*";
|
|
}
|
|
cout << endl;
|
|
}
|
|
} else {
|
|
for (size_t bin : bins) {
|
|
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin) / max_bin_count));
|
|
|
|
if (bin < 100) cout << " ";
|
|
if (bin < 10) cout << " ";
|
|
cout << bin << "|";
|
|
|
|
for (size_t j = 0; j < height; j++) {
|
|
cout << "*";
|
|
}
|
|
cout << endl;
|
|
}
|
|
}
|
|
}
|