Сравнить коммиты
Ничего общего в коммитах. 'f67263f06336e05a04d3e375039301256e17868a' и 'a264f738e0cf076378376c90e602ff806c6d1994' имеют совершенно разные истории.
f67263f063
...
a264f738e0
@ -1,34 +1,92 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
|
||||||
#include "text.h"
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct Input {
|
int main(){
|
||||||
vector<double> numbers;
|
|
||||||
size_t bin_count{};
|
const size_t SCREEN_WIDTH = 80;
|
||||||
};
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1;
|
||||||
|
size_t bin_count, counts;
|
||||||
Input
|
cerr << "Enter counts:";
|
||||||
input_data(){
|
cin >> counts;
|
||||||
Input in;
|
|
||||||
size_t number_count;
|
vector <double> numbers(counts);
|
||||||
cin >> number_count;
|
|
||||||
in.numbers.resize(number_count);
|
for (size_t i = 0; i < counts; i++){
|
||||||
|
cerr << "Enter array "<< i <<" number:";
|
||||||
vector<double> numbers(number_count);
|
cin >> numbers[i];
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
|
||||||
cin >> in.numbers[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cin >> in.bin_count;
|
cerr << "Enter bin_count:";
|
||||||
return in;
|
cin >> bin_count;
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
double minN = numbers[0], maxN = numbers[0];
|
||||||
size_t max_count;
|
|
||||||
auto in = input_data();
|
for (double x: numbers){
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
if (minN > x){
|
||||||
show_histogram_text(bins,in.bin_count, max_count);
|
minN = x;
|
||||||
return 0;
|
}
|
||||||
|
if (maxN < x){
|
||||||
|
maxN = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double diff = (maxN - minN) / bin_count;
|
||||||
|
|
||||||
|
vector <size_t> bins(bin_count);
|
||||||
|
|
||||||
|
size_t max_count = 0;
|
||||||
|
for (size_t i = 0; i < counts; i++){
|
||||||
|
bool found = false;
|
||||||
|
for (size_t j = 0;(j < bin_count - 1) && !found; j++){
|
||||||
|
auto lo = minN + j * diff;
|
||||||
|
auto hi = minN + (j + 1) * diff;
|
||||||
|
if ((lo <= numbers[i]) && (hi > numbers[i])){
|
||||||
|
bins[j]++;
|
||||||
|
if (bins[j] > max_count){
|
||||||
|
max_count = bins[j];
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found){
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
if (bins[bin_count - 1] > max_count){
|
||||||
|
max_count = bins[bin_count - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool scaling = false;
|
||||||
|
|
||||||
|
if (max_count > MAX_ASTERISK){
|
||||||
|
scaling = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < bin_count; i++){
|
||||||
|
cout << " ";
|
||||||
|
if (bins[i] < 100){
|
||||||
|
cout << ' ';
|
||||||
|
}
|
||||||
|
if (bins[i] < 10){
|
||||||
|
cout << ' ';
|
||||||
|
}
|
||||||
|
cout << bins[i] << '|';
|
||||||
|
|
||||||
|
size_t number_of_stars = bins[i];
|
||||||
|
|
||||||
|
if (scaling){
|
||||||
|
if (bins[i] == max_count){
|
||||||
|
number_of_stars = MAX_ASTERISK * 1.0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t j = 0; j < number_of_stars; j++){
|
||||||
|
cout << '*';
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче