Родитель
0a70cb4524
Сommit
ec9c2d496f
@ -0,0 +1,35 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
const size_t SCREEN_WIDTH = 80;
|
||||||
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
|
||||||
|
void
|
||||||
|
show_histogram_text(vector<size_t> bins) {
|
||||||
|
size_t bin_max_size = 0;
|
||||||
|
for (auto bin : bins) {
|
||||||
|
if (bin_max_size < bin) {
|
||||||
|
bin_max_size = bin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double k = double(MAX_ASTERISK) / bin_max_size;
|
||||||
|
if (k > 1) {
|
||||||
|
k = 1;
|
||||||
|
}
|
||||||
|
for (size_t bin = 0; bin < bins.size(); bin++) {
|
||||||
|
if (bins[bin] < 100) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
if (bins[bin] < 10) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
cout << bins[bin] << "|";
|
||||||
|
for (size_t i = 0; i < bins[bin] * k; i++) {
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче