Сommit
a94ec184bf
@ -0,0 +1,2 @@
|
|||||||
|
/bin
|
||||||
|
/obj
|
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="Lab1" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/Lab1" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/Lab1" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-fexceptions" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="main.cpp" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
@ -0,0 +1,110 @@
|
|||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void mmV(vector<double> numbers, double& min, double& max);
|
||||||
|
size_t maxBin(vector<size_t> bins);
|
||||||
|
|
||||||
|
const size_t SCREEN_WIDTH = 80;
|
||||||
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
vector<double> numbers;
|
||||||
|
vector<size_t> bins;
|
||||||
|
size_t countOfNumbers;
|
||||||
|
size_t binCount;
|
||||||
|
size_t maxCount;
|
||||||
|
double max;
|
||||||
|
double min;
|
||||||
|
cerr << "Input your count of numbers:\n";
|
||||||
|
cin >> countOfNumbers;
|
||||||
|
numbers.resize(countOfNumbers);
|
||||||
|
cerr << "Input numbers:\n";
|
||||||
|
for (int i = 0; i < countOfNumbers; i++) {
|
||||||
|
cerr << i << endl;
|
||||||
|
cin >> numbers[i];
|
||||||
|
}
|
||||||
|
cerr << endl;
|
||||||
|
cerr << "Input bin count:\n";
|
||||||
|
cin >> binCount;
|
||||||
|
bins.resize(binCount);
|
||||||
|
mmV(numbers, min, max);
|
||||||
|
double bin_size = (max - min) / binCount;
|
||||||
|
|
||||||
|
|
||||||
|
for (size_t i = 0; i < countOfNumbers; i++) {
|
||||||
|
bool found = false;
|
||||||
|
for (size_t j = 0; (j < binCount - 1) && !found; j++) {
|
||||||
|
auto lo = min + j * bin_size;
|
||||||
|
auto hi = min + (j + 1) * bin_size;
|
||||||
|
if ((lo <= numbers[i]) && (hi > numbers[i])) {
|
||||||
|
bins[j]++;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
bins[binCount - 1]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxCount = maxBin(bins);
|
||||||
|
size_t count_stars;
|
||||||
|
for (int i = 0; i < binCount; i++) {
|
||||||
|
|
||||||
|
if (bins[i] < 100) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
if (bins[i] < 10) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << bins[i];
|
||||||
|
cout << "|";
|
||||||
|
|
||||||
|
if (maxCount > MAX_ASTERISK) {
|
||||||
|
count_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / maxCount);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count_stars = bins[i];
|
||||||
|
}
|
||||||
|
for (size_t i2 = 0; i2 < count_stars; i2++) {
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t maxBin(vector<size_t> bins) { //ëó÷øå áåç ôóíêöèè
|
||||||
|
size_t max = bins[0];
|
||||||
|
for (int i = 1; i < bins.size(); i++) {
|
||||||
|
if (max < bins[i]) {
|
||||||
|
max = bins[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
void mmV(vector<double> numbers, double& min, double& max) { //ñêàçàë ñäåëàòü áåç ôóíêöèè
|
||||||
|
min = numbers[0];
|
||||||
|
max = numbers[0];
|
||||||
|
for (double number : numbers) {
|
||||||
|
if (min > number) {
|
||||||
|
min = number;
|
||||||
|
}
|
||||||
|
if (max < number) {
|
||||||
|
max = number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//var15 áåç ìàñøòàáèðîâàíèÿ çàùèòà
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче