Сравнить коммиты
3 Коммитов
12f9821f95
...
53f1e4e9a8
Автор | SHA1 | Дата |
---|---|---|
|
53f1e4e9a8 | 12 месяцев назад |
|
6e9139fe35 | 12 месяцев назад |
|
0bac1c1317 | 12 месяцев назад |
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -0,0 +1,82 @@
|
||||
# depslib dependency file v1.0
|
||||
1713791550 source:c:\users\u113-02\desktop\hehehe\main.cpp
|
||||
<vector>
|
||||
<iostream>
|
||||
<cmath>
|
||||
|
||||
1714330914 source:e:\hehehe\main.cpp
|
||||
<vector>
|
||||
<iostream>
|
||||
<cmath>
|
||||
|
||||
1714921863 source:c:\users\nick\desktop\hehehe\main.cpp
|
||||
<vector>
|
||||
<iostream>
|
||||
<cmath>
|
||||
"histogram.h"
|
||||
"svg.h"
|
||||
"text.h"
|
||||
|
||||
1714861965 c:\users\nick\desktop\hehehe\histogram.h
|
||||
<vector>
|
||||
|
||||
1714862011 source:c:\users\nick\desktop\hehehe\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
<iostream>
|
||||
|
||||
1714919929 source:c:\users\nick\desktop\hehehe\svg.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<string>
|
||||
"svg.h"
|
||||
|
||||
1714919958 c:\users\nick\desktop\hehehe\svg.h
|
||||
<vector>
|
||||
<string>
|
||||
|
||||
1714921819 c:\users\nick\desktop\hehehe\text.h
|
||||
<vector>
|
||||
|
||||
1714921889 source:c:\users\nick\desktop\hehehe\text.cpp
|
||||
"text.h"
|
||||
"svg.h"
|
||||
<string>
|
||||
<iostream>
|
||||
|
||||
1714862012 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
<iostream>
|
||||
|
||||
1714861966 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.h
|
||||
<vector>
|
||||
|
||||
1714997928 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\main.cpp
|
||||
<vector>
|
||||
<iostream>
|
||||
<cmath>
|
||||
"histogram.h"
|
||||
"svg.h"
|
||||
"text.h"
|
||||
|
||||
1714997791 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\svg.h
|
||||
<vector>
|
||||
<string>
|
||||
|
||||
1714996911 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\text.h
|
||||
<vector>
|
||||
|
||||
1714997791 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\text.cpp
|
||||
"text.h"
|
||||
"svg.h"
|
||||
<string>
|
||||
<iostream>
|
||||
"text.h"
|
||||
|
||||
1714997285 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\svg.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<string>
|
||||
"svg.h"
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="113" topLine="58" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1097" topLine="20" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="736" topLine="18" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="948" topLine="18" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
@ -0,0 +1,43 @@
|
||||
#include "histogram.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers) {
|
||||
if (x < min) {
|
||||
min = x;
|
||||
}
|
||||
else if (x > max) {
|
||||
max = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<double>
|
||||
make_histogram(const std::vector<double>& numbers, size_t bin_count) {
|
||||
vector<double> bins(bin_count);
|
||||
|
||||
double min = 0, max = 0;
|
||||
find_minmax(numbers, min, max);
|
||||
|
||||
double bin_size = (max - min) / bin_count;
|
||||
for (int i = 0; i < numbers.size(); i++) {
|
||||
bool found = false;
|
||||
for (int 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]++;
|
||||
}
|
||||
}
|
||||
return bins;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
std::vector<double>
|
||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
void
|
||||
find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
@ -1,110 +1,83 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include<cmath>
|
||||
#include "histogram.h"
|
||||
#include "svg.h"
|
||||
#include "text.h"
|
||||
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
size_t SCREEN_WIDTH;
|
||||
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
size_t SCREEN_WIDTH{};
|
||||
size_t number_count{};
|
||||
|
||||
};
|
||||
|
||||
Input
|
||||
input_data() {
|
||||
|
||||
|
||||
size_t number_count;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
Input in;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> in.number_count;
|
||||
in.numbers.resize(in.number_count);
|
||||
for (size_t i = 0; i < in.number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
cerr<<"Enter bin count:";
|
||||
cin >> in.bin_count;
|
||||
|
||||
|
||||
|
||||
while (true) {
|
||||
cerr << "Screen width: ";
|
||||
cin >> SCREEN_WIDTH;
|
||||
if (SCREEN_WIDTH < 7) {
|
||||
while (true) {
|
||||
//cerr << "Screen width: ";
|
||||
//cin >> in.SCREEN_WIDTH;
|
||||
in.SCREEN_WIDTH=80;
|
||||
if (in.SCREEN_WIDTH < 7) {
|
||||
cerr << "<7"; cerr << endl;
|
||||
continue;
|
||||
}
|
||||
if (SCREEN_WIDTH > 80) {
|
||||
}
|
||||
if (in.SCREEN_WIDTH > 80) {
|
||||
cerr << ">80"; cerr << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (SCREEN_WIDTH < (number_count / 3)){
|
||||
if (in.SCREEN_WIDTH < (in.number_count / 3)){
|
||||
cerr << "<number_count/3"; cerr << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
vector<double> numbers(number_count);
|
||||
cerr << "Enter numbers: ";
|
||||
for (int i = 0; i < number_count; i++)
|
||||
{
|
||||
cin >> numbers[i];
|
||||
|
||||
}
|
||||
double min = numbers[0];
|
||||
double max = numbers[0];
|
||||
for (double x : numbers)
|
||||
{
|
||||
if (x < min)
|
||||
min = x;
|
||||
else if (x > max)
|
||||
max = x;
|
||||
}
|
||||
size_t bin_count;
|
||||
cerr<<"Enter bin count:";
|
||||
cin >> bin_count;
|
||||
vector<size_t> bins(bin_count);
|
||||
double bin_size = (max - min) / bin_count;
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
bool found = false;
|
||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||
{
|
||||
auto low = min + j * bin_size;
|
||||
auto high = min + (j + 1) * bin_size;
|
||||
if ((low <= numbers[i]) && (numbers[i] < high))
|
||||
{
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
bins[bin_count - 1]++;
|
||||
}
|
||||
}
|
||||
|
||||
double mxbins = bins[0];
|
||||
|
||||
for (double x : bins)
|
||||
{
|
||||
if (x > mxbins)
|
||||
mxbins = x;
|
||||
}
|
||||
double k;
|
||||
|
||||
if (mxbins > MAX_ASTERISK)
|
||||
k = MAX_ASTERISK / mxbins;
|
||||
else
|
||||
k = 1;
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] < 10) {
|
||||
cout << " " << bins[i] << "|";
|
||||
}
|
||||
else if (bins[i] < 100) {
|
||||
cout << " " << bins[i] << "|";
|
||||
}
|
||||
else if (bins[i] < 1000) {
|
||||
cout << bins[i] << "|";
|
||||
|
||||
}
|
||||
for (int j = 0; j < floor(bins[i] * k); j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
auto in = input_data();
|
||||
|
||||
double min, max;
|
||||
|
||||
|
||||
|
||||
|
||||
const size_t MAX_ASTERISK = in.SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
|
||||
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
|
||||
|
||||
|
||||
|
||||
//show_histogram_text(bins, MAX_ASTERISK, in.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "svg.h"
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
svg_begin(double width, double height) {
|
||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
cout << "<svg ";
|
||||
cout << "width='" << width << "' ";
|
||||
cout << "height='" << height << "' ";
|
||||
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_end() {
|
||||
cout << "</svg>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
||||
}
|
||||
|
||||
void
|
||||
svg_rect(double x, double y, double width, double height, string stroke, string fill) {
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />";
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<double>& bins) {
|
||||
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto MAX_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
|
||||
|
||||
double max_count = (bins[0] * BLOCK_WIDTH);
|
||||
for (double bin : bins) {
|
||||
if ((bin * BLOCK_WIDTH) > max_count) {
|
||||
max_count = (bin * BLOCK_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
svg_begin(400, 300);
|
||||
double top = 0;
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", "#00ffff");
|
||||
top += 2*BIN_HEIGHT;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <string>
|
||||
void show_histogram_svg(const std::vector<double>& bins);
|
||||
|
@ -0,0 +1,42 @@
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "text.h"
|
||||
using namespace std;
|
||||
|
||||
void show_histogram_text (const std::vector<double>& bins, size_t MAX_ASTERISK, size_t bin_count)
|
||||
{
|
||||
double mxbins = bins[0];
|
||||
|
||||
for (double x : bins)
|
||||
{
|
||||
if (x > mxbins)
|
||||
mxbins = x;
|
||||
}
|
||||
double k;
|
||||
|
||||
if (mxbins > MAX_ASTERISK)
|
||||
k = MAX_ASTERISK / mxbins;
|
||||
else
|
||||
k = 1;
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] < 10) {
|
||||
cout << " " << bins[i] << "|";
|
||||
}
|
||||
else if (bins[i] < 100) {
|
||||
cout << " " << bins[i] << "|";
|
||||
}
|
||||
else if (bins[i] < 1000) {
|
||||
cout << bins[i] << "|";
|
||||
|
||||
}
|
||||
for (int j = 0; j < int(bins[i] * k); j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(const std::vector<double>& bins, size_t MAX_ASTERISK, size_t bin_count);
|
||||
|
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="unittest" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/unittest" 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/unittest" 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" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
@ -0,0 +1,12 @@
|
||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
# depslib dependency file v1.0
|
||||
1714862011 source:c:\users\nick\desktop\hehehe\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
<iostream>
|
||||
|
||||
1714861965 c:\users\nick\desktop\hehehe\histogram.h
|
||||
<vector>
|
||||
|
||||
1714917108 source:c:\users\nick\desktop\hehehe\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1714916946 c:\users\nick\desktop\hehehe\doctest.h
|
||||
<signal.h>
|
||||
<ciso646>
|
||||
<cstddef>
|
||||
<ostream>
|
||||
<istream>
|
||||
<type_traits>
|
||||
"doctest_fwd.h"
|
||||
<ctime>
|
||||
<cmath>
|
||||
<climits>
|
||||
<math.h>
|
||||
<new>
|
||||
<cstdio>
|
||||
<cstdlib>
|
||||
<cstring>
|
||||
<limits>
|
||||
<utility>
|
||||
<fstream>
|
||||
<sstream>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
<iomanip>
|
||||
<vector>
|
||||
<atomic>
|
||||
<mutex>
|
||||
<set>
|
||||
<map>
|
||||
<unordered_set>
|
||||
<exception>
|
||||
<stdexcept>
|
||||
<csignal>
|
||||
<cfloat>
|
||||
<cctype>
|
||||
<cstdint>
|
||||
<string>
|
||||
<sys/types.h>
|
||||
<unistd.h>
|
||||
<sys/sysctl.h>
|
||||
<AfxWin.h>
|
||||
<windows.h>
|
||||
<io.h>
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1714862096 c:\users\nick\desktop\hehehe\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1714862012 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
<iostream>
|
||||
|
||||
1714861966 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram.h
|
||||
<vector>
|
||||
|
||||
1714917110 source:c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1714916948 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\doctest.h
|
||||
<signal.h>
|
||||
<ciso646>
|
||||
<cstddef>
|
||||
<ostream>
|
||||
<istream>
|
||||
<type_traits>
|
||||
"doctest_fwd.h"
|
||||
<ctime>
|
||||
<cmath>
|
||||
<climits>
|
||||
<math.h>
|
||||
<new>
|
||||
<cstdio>
|
||||
<cstdlib>
|
||||
<cstring>
|
||||
<limits>
|
||||
<utility>
|
||||
<fstream>
|
||||
<sstream>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
<iomanip>
|
||||
<vector>
|
||||
<atomic>
|
||||
<mutex>
|
||||
<set>
|
||||
<map>
|
||||
<unordered_set>
|
||||
<exception>
|
||||
<stdexcept>
|
||||
<csignal>
|
||||
<cfloat>
|
||||
<cctype>
|
||||
<cstdint>
|
||||
<string>
|
||||
<sys/types.h>
|
||||
<unistd.h>
|
||||
<sys/sysctl.h>
|
||||
<AfxWin.h>
|
||||
<windows.h>
|
||||
<io.h>
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1714862098 c:\users\u113-02\desktop\aaaaaaaaaaaaaaaaaaa\histogram_internal.h
|
||||
<vector>
|
||||
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
</CodeBlocks_layout_file>
|
Загрузка…
Ссылка в новой задаче