Сравнить коммиты
Ничего общего в коммитах. 'b7e2e9af4279ca89506893eef6db61b199ae70c3' и '881bd34b2a3ad0b1dcf7789ea3c6df5f33a2f5db' имеют совершенно разные истории.
b7e2e9af42
...
881bd34b2a
@ -1,38 +1,85 @@
|
|||||||
#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;
|
||||||
|
|
||||||
struct Input {
|
int main()
|
||||||
vector<double> numbers;
|
{
|
||||||
size_t bin_count{};
|
const size_t SCREEN_WIDTH = 80;
|
||||||
size_t block_width{};
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
};
|
|
||||||
|
|
||||||
Input input_data(istream& in_steam = cin) {
|
size_t number_count;
|
||||||
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];
|
||||||
|
}
|
||||||
|
|
||||||
Input in;
|
|
||||||
in.numbers.resize(number_count);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
size_t bin_count;
|
||||||
cin >> in.numbers[i];
|
|
||||||
}
|
|
||||||
cerr << "Enter bin count: ";
|
cerr << "Enter bin count: ";
|
||||||
cin >> in.bin_count;
|
cin >> bin_count;
|
||||||
|
vector<size_t> bins(bin_count, 0);
|
||||||
|
|
||||||
return in;
|
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;
|
||||||
|
|
||||||
|
for(size_t i = 0; i<number_count; i++){
|
||||||
|
bool found = false;
|
||||||
|
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 ]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t max_count = bins[0];
|
||||||
|
for (size_t i=0;i<bin_count;i++){
|
||||||
|
if (bins[i]>max_count){
|
||||||
|
max_count = bins[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
for (size_t i = 0; i < bin_count; i++) {
|
||||||
auto in = input_data();
|
if (bins[i] < 10) {
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
cout << " " << bins[i] << "|";
|
||||||
show_histogram_svg(bins, in.block_width);
|
}
|
||||||
|
else if (bins[i] < 100) {
|
||||||
|
cout << " " << bins[i] << "|";
|
||||||
|
}
|
||||||
|
else if (bins[i] < 1000) {
|
||||||
|
cout << bins[i] << "|";
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t height;
|
||||||
|
if (max_count <= MAX_ASTERISK){
|
||||||
|
height = bins[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
height = MAX_ASTERISK*(static_cast<double>(bins[i])/max_count);
|
||||||
|
}
|
||||||
|
for (size_t j=0; j<height;j++){
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
Ссылка в новой задаче