|
|
@ -2,9 +2,11 @@
|
|
|
|
#include <conio.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
|
|
|
#include "text.h"
|
|
|
|
|
|
|
|
#include "svg01.h"
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
const size_t MAX_ELEMENT = 76;
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
struct Input {
|
|
|
|
vector<double> numbers;
|
|
|
|
vector<double> numbers;
|
|
|
|
size_t bin_count{};
|
|
|
|
size_t bin_count{};
|
|
|
@ -31,113 +33,11 @@ input_data(){
|
|
|
|
return in;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max){
|
|
|
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
|
|
|
for(size_t i=0; i < numbers.size(); i++){
|
|
|
|
|
|
|
|
if (numbers[i] < min)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
min = numbers[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (numbers[i] > max)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
max = numbers[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<size_t>
|
|
|
|
|
|
|
|
make_histogram(const vector<double>& numbers, size_t bin_count){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double min, max;
|
|
|
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto lower_Bound = min + j * bin_size;
|
|
|
|
|
|
|
|
auto upper_Bound = min + (j + 1) * bin_size;
|
|
|
|
|
|
|
|
if ((lower_Bound <= numbers[i]) && (numbers[i] < upper_Bound))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bins[j]++;
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double max_count = bins[0];
|
|
|
|
|
|
|
|
for (size_t j=0; j < bin_count; j++){
|
|
|
|
|
|
|
|
if (bins[j] > max_count) {
|
|
|
|
|
|
|
|
max_count = bins[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return bins;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
show_histogram_text(const vector<size_t> bins, size_t bin_count){
|
|
|
|
|
|
|
|
double max_count = bins[0];
|
|
|
|
|
|
|
|
for (size_t j=0; j < bin_count; j++){
|
|
|
|
|
|
|
|
if (bins[j] > max_count) {
|
|
|
|
|
|
|
|
max_count = bins[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<size_t> height(bin_count);
|
|
|
|
|
|
|
|
for (size_t j=0; j < bin_count; j++){
|
|
|
|
|
|
|
|
height[j] = MAX_ELEMENT * (bins[j]/max_count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (max_count > MAX_ELEMENT){
|
|
|
|
|
|
|
|
for (size_t j=0; j < bin_count; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bins[j] < 100) {
|
|
|
|
|
|
|
|
cout << " ";
|
|
|
|
|
|
|
|
if (bins[j] < 10){
|
|
|
|
|
|
|
|
cout << " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << bins[j] << "|";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i=0; i < height[j]; i++){
|
|
|
|
|
|
|
|
cout << "*";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
for (size_t j=0; j < bin_count; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bins[j] < 100) {
|
|
|
|
|
|
|
|
cout << " ";
|
|
|
|
|
|
|
|
if (bins[j] < 10){
|
|
|
|
|
|
|
|
cout << " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << bins[j] << "|";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i=0; i < bins[j];i++){
|
|
|
|
|
|
|
|
cout << "*";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
auto in = input_data();
|
|
|
|
auto in = input_data();
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
show_histogram_text(bins, in.bin_count);
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|