Сравнить коммиты
4 Коммитов
881bd34b2a
...
b7e2e9af42
Автор | SHA1 | Дата |
---|---|---|
![]() |
b7e2e9af42 | 4 недель назад |
![]() |
da84686c71 | 1 месяц назад |
![]() |
1a7558d214 | 2 месяцев назад |
![]() |
056cafb485 | 2 месяцев назад |
@ -1,85 +1,38 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
|
//#include "doctest.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
struct Input {
|
||||||
{
|
vector<double> numbers;
|
||||||
const size_t SCREEN_WIDTH = 80;
|
size_t bin_count{};
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
size_t block_width{};
|
||||||
|
};
|
||||||
|
|
||||||
size_t number_count;
|
Input input_data(istream& in_steam = cin) {
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
cin >> number_count;
|
cin >> number_count;
|
||||||
vector<double> numbers(number_count);
|
|
||||||
for (size_t i=0;i<number_count;i++){
|
|
||||||
cin >> numbers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t bin_count;
|
|
||||||
cerr << "Enter bin count: ";
|
|
||||||
cin >> bin_count;
|
|
||||||
vector<size_t> bins(bin_count, 0);
|
|
||||||
|
|
||||||
double min = numbers[0];
|
|
||||||
double max = numbers[0];
|
|
||||||
for (double x: numbers) {
|
|
||||||
if (x<min) {
|
|
||||||
min = x;
|
|
||||||
}
|
|
||||||
else if (x > max) {
|
|
||||||
max = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double bin_size = (max - min) / bin_count;
|
Input in;
|
||||||
|
in.numbers.resize(number_count);
|
||||||
|
|
||||||
for(size_t i = 0; i<number_count; i++){
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
bool found = false;
|
cin >> in.numbers[i];
|
||||||
for(size_t j=0; (j<bin_count-1) && !found; j++){
|
|
||||||
auto lo = min + j*bin_size;
|
|
||||||
auto hi = min+(j+1)*bin_size;
|
|
||||||
if((lo<= numbers[i]) && (numbers[i] < hi)){
|
|
||||||
bins[j]++;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!found){
|
|
||||||
bins[bin_count - 1 ]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
cerr << "Enter bin count: ";
|
||||||
|
cin >> in.bin_count;
|
||||||
|
|
||||||
size_t max_count = bins[0];
|
return in;
|
||||||
for (size_t i=0;i<bin_count;i++){
|
}
|
||||||
if (bins[i]>max_count){
|
|
||||||
max_count = bins[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
|
||||||
if (bins[i] < 10) {
|
|
||||||
cout << " " << bins[i] << "|";
|
|
||||||
}
|
|
||||||
else if (bins[i] < 100) {
|
|
||||||
cout << " " << bins[i] << "|";
|
|
||||||
}
|
|
||||||
else if (bins[i] < 1000) {
|
|
||||||
cout << bins[i] << "|";
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t height;
|
int main() {
|
||||||
if (max_count <= MAX_ASTERISK){
|
auto in = input_data();
|
||||||
height = bins[i];
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
}
|
show_histogram_svg(bins, in.block_width);
|
||||||
else {
|
|
||||||
height = MAX_ASTERISK*(static_cast<double>(bins[i])/max_count);
|
|
||||||
}
|
|
||||||
for (size_t j=0; j<height;j++){
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
Ссылка в новой задаче