Сравнить коммиты
2 Коммитов
a264f738e0
...
f67263f063
Автор | SHA1 | Дата |
---|---|---|
![]() |
f67263f063 | 2 лет назад |
![]() |
4ec4a7cd73 | 2 лет назад |
@ -1,92 +1,34 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.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 - 6 - 1;
|
};
|
||||||
size_t bin_count, counts;
|
|
||||||
cerr << "Enter counts:";
|
Input
|
||||||
cin >> counts;
|
input_data(){
|
||||||
|
Input in;
|
||||||
vector <double> numbers(counts);
|
size_t number_count;
|
||||||
|
cin >> number_count;
|
||||||
for (size_t i = 0; i < counts; i++){
|
in.numbers.resize(number_count);
|
||||||
cerr << "Enter array "<< i <<" number:";
|
|
||||||
cin >> numbers[i];
|
vector<double> numbers(number_count);
|
||||||
}
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
|
cin >> in.numbers[i];
|
||||||
cerr << "Enter bin_count:";
|
|
||||||
cin >> bin_count;
|
|
||||||
|
|
||||||
double minN = numbers[0], maxN = numbers[0];
|
|
||||||
|
|
||||||
for (double x: numbers){
|
|
||||||
if (minN > x){
|
|
||||||
minN = x;
|
|
||||||
}
|
|
||||||
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++){
|
cin >> in.bin_count;
|
||||||
cout << " ";
|
return in;
|
||||||
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++){
|
int main(){
|
||||||
cout << '*';
|
size_t max_count;
|
||||||
}
|
auto in = input_data();
|
||||||
cout << endl;
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
}
|
show_histogram_text(bins,in.bin_count, max_count);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче