Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
44 строки
992 B
C++
44 строки
992 B
C++
#include "text.h"
|
|
#include <vector>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
const size_t MAX_LENGTH = SCREEN_WIDTH - 3 - 1;
|
|
|
|
void
|
|
show_histogram_text(vector<size_t> bins, size_t bin_count ){
|
|
auto max_count = bins[0];
|
|
for (auto x : bins) {
|
|
if (x > max_count) {
|
|
max_count = x;
|
|
}
|
|
}
|
|
for (size_t i = 0; i < bin_count; i++) {
|
|
size_t j = 100;
|
|
while (bins[i] < j) {
|
|
cout << " ";
|
|
j /= 10;
|
|
}
|
|
cout << bins[i] << "|";
|
|
if (max_count > MAX_LENGTH) {
|
|
auto count = bins[i];
|
|
size_t height = MAX_LENGTH * (static_cast<double>(count) / max_count);
|
|
j = 0;
|
|
while (j < height) {
|
|
cout << "*";
|
|
j++;
|
|
}
|
|
}
|
|
else {
|
|
j = 0;
|
|
while (j < bins[i]) {
|
|
cout << "*";
|
|
j++;
|
|
}
|
|
}
|
|
cout << endl;
|
|
}
|
|
}
|