From 191fd262a095a175ecacc157c3c015f64ae2b3ba Mon Sep 17 00:00:00 2001 From: MatusSV Date: Mon, 27 May 2024 07:50:45 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=B8=D0=B7=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 14 +++++++------- svg.cpp | 1 + svg.h | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 4960f04..c0121b0 100644 --- a/main.cpp +++ b/main.cpp @@ -14,31 +14,31 @@ struct Input { }; Input -input_data() { +input_data(istream& in_stream) { size_t number_count; Input in; cerr << "Enter number count: "; - cin >> number_count; + in_stream >> number_count; vector numbers(number_count); in.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) { - cin >> in.numbers[i]; + in_stream >> in.numbers[i]; } cerr << "Enter bins count and colors: "; - cin >> in.bin_count; + in_stream >> in.bin_count; vector colors(in.bin_count); in.colors.resize(in.bin_count); for (size_t i = 0; i < in.bin_count; i++) { - cin >> in.colors[i]; + in_stream >> in.colors[i]; bool check = check_color(in.colors[i]); while (!check) { cerr << "Incorrect input. Color doesn't contain # or has spaces." << endl; - cin >> in.colors[i]; + in_stream >> in.colors[i]; check = check_color(in.colors[i]); } } @@ -47,7 +47,7 @@ input_data() { int main() { - Input in = input_data(); + auto in = input_data(cin); vector bins = make_histogram(in.numbers, in.bin_count); //show_histogram_text(bins, in.bin_count); show_histogram_svg(bins, in.colors); diff --git a/svg.cpp b/svg.cpp index 386bb4f..7cbe0ca 100644 --- a/svg.cpp +++ b/svg.cpp @@ -7,6 +7,7 @@ using namespace std; bool check_color(string color) { + if (color[0]=='#'||color.find(' ')==(-1)) return true; else diff --git a/svg.h b/svg.h index 204dd8a..d14aa0a 100644 --- a/svg.h +++ b/svg.h @@ -7,4 +7,7 @@ void show_histogram_svg(const std::vector& bins, const std::vector& colors); +bool +check_color(std::string color); + #endif // SVG_H_INCLUDED