Сравнить коммиты
Ничего общего в коммитах. 'b44991fd54f05f8c13ee96b53aba5b7ccd405a01' и '36a4267a9e365a0444672a29a7b98f6b957e4f6e' имеют совершенно разные истории.
b44991fd54
...
36a4267a9e
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,39 +1,111 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "histogram_internal.h"
|
|
||||||
#include "svg.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
struct Input {
|
|
||||||
vector<double> numbers;
|
int main()
|
||||||
size_t bin_count{};
|
{
|
||||||
};
|
const size_t SCREEN_WIDTH = 80;
|
||||||
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
Input
|
size_t number_count;//êîëâî ÷èñåë
|
||||||
input_data(){
|
cerr << "Enter number count: ";
|
||||||
Input in;
|
|
||||||
size_t number_count;
|
|
||||||
cerr << "Enter numbers count: ";
|
|
||||||
cin >> number_count;
|
cin >> number_count;
|
||||||
in.numbers.resize(number_count);
|
vector<double> numbers(number_count); //ìàññèâ ÷èñåë
|
||||||
|
|
||||||
cerr << "Enter numbers: ";
|
//ââîä çíà÷åíèé
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i=0; i<number_count; i++)
|
||||||
cin >> in.numbers[i];
|
{
|
||||||
|
cin >> numbers[i];
|
||||||
}
|
}
|
||||||
|
size_t bin_count;
|
||||||
cerr << "Enter bin count: ";
|
cerr << "Enter bin count: ";
|
||||||
cin >> in.bin_count;
|
cin >> bin_count;
|
||||||
|
|
||||||
|
vector<size_t> bins(bin_count); //ìàññèâ êîëâà ÷èñåë â êîðçèíàõ
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
double bin_size = (max - min) / bin_count; //ðàçìåð êîðçèíû
|
||||||
{
|
|
||||||
auto in = input_data();
|
for (size_t i = 0; i < number_count; i++)
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
{
|
||||||
show_histogram_svg(bins, in.bin_count);
|
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]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double max_count;
|
||||||
|
|
||||||
|
//ìàêñèìàäáíîå êîëâî ÷èñåë â êîðçèíå ñðåäè âñåõ êîðçèí
|
||||||
|
max_count = bins[0];
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
size_t height;
|
||||||
|
if (max_count <= MAX_ASTERISK)
|
||||||
|
{
|
||||||
|
height = bins[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (bins [i] < max_count){
|
||||||
|
size_t pr_count = max_count - bins[i];
|
||||||
|
for (size_t k = 0; k < pr_count; k++){
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t j = 0; j < height; j++)
|
||||||
|
{
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << "|";
|
||||||
|
|
||||||
|
if (bins[i] < 100)
|
||||||
|
{
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
if (bins[i] < 10)
|
||||||
|
{
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
cout << bins[i] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче