Popko Egor 1 месяц назад
Родитель 8c0597f45f
Сommit 228292835f

@ -1,5 +1,7 @@
#include <iostream>
#include <vector>
#include "histogram.h"
#include "svg.h"
using namespace std;
@ -26,45 +28,9 @@ Input input_data()
return in;
}
void find_minmax(const vector<double>& numbers, double& min, double& max) {
if (numbers.empty()) {
return;
}
min = numbers[0];
max = numbers[0];
for (double x : numbers) {
if (x < min) min = x;
if (x > max) max = x;
}
}
int main() {
auto in = input_data();
double min, max;
find_minmax(in.numbers, min, max);
vector<size_t> bins(in.bin_count);
for (double x : in.numbers) {
size_t bin_index = (x - min) / (max - min) * in.bin_count;
if (bin_index == in.bin_count) bin_index--;
bins[bin_index]++;
}
const size_t SCREEN_WIDTH = 80;
size_t max_count = 0;
for (size_t count : bins) {
if (count > max_count) max_count = count;
}
for (size_t bin : bins) {
size_t height = bin * SCREEN_WIDTH / max_count;
for (size_t i = 0; i < height; i++) {
cout << '*';
}
cout << endl;
}
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;
}

Загрузка…
Отмена
Сохранить