From dec7e67766bd59abde57bfeaa129c38451edb146 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 28 Nov 2025 21:25:58 +0500 Subject: [PATCH 01/23] add solution: add condition task --- 01_week/tasks/addition/addition.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/01_week/tasks/addition/addition.cpp b/01_week/tasks/addition/addition.cpp index 92872802..f1e9d03d 100644 --- a/01_week/tasks/addition/addition.cpp +++ b/01_week/tasks/addition/addition.cpp @@ -3,5 +3,7 @@ int64_t Addition(int a, int b) { - throw std::runtime_error{"Not implemented"}; + int64_t c = static_cast(a); + int64_t d = static_cast(b); + return c + d; } \ No newline at end of file From 06c5afb61de0c7583fc4ed2242a22310aa7c219e Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 28 Nov 2025 21:59:30 +0500 Subject: [PATCH 02/23] add solution: add rms task --- 01_week/tasks/rms/rms.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/01_week/tasks/rms/rms.cpp b/01_week/tasks/rms/rms.cpp index 6882f0a9..ab1fd95d 100644 --- a/01_week/tasks/rms/rms.cpp +++ b/01_week/tasks/rms/rms.cpp @@ -1,7 +1,15 @@ -#include +#include #include +#include double CalculateRMS(double values[], size_t size) { - throw std::runtime_error{"Not implemented"}; + if (size == 0 || values == nullptr){ + return 0.0; + } + double rms = 0; + for (size_t i = 0; i < size; ++i){ + rms += values[i] * values[i]; + } + return sqrt(rms/size); } \ No newline at end of file From a3f7150e19c00c2ac6f96f530cb405ea192919ff Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 28 Nov 2025 22:38:42 +0500 Subject: [PATCH 03/23] add solution: add print_bits task --- 01_week/tasks/print_bits/print_bits.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/01_week/tasks/print_bits/print_bits.cpp b/01_week/tasks/print_bits/print_bits.cpp index a48a43c1..35c9d291 100644 --- a/01_week/tasks/print_bits/print_bits.cpp +++ b/01_week/tasks/print_bits/print_bits.cpp @@ -1,7 +1,17 @@ #include #include +#include void PrintBits(long long value, size_t bytes) { - throw std::runtime_error{"Not implemented"}; + if (bytes > 0 && bytes <= 8){ + std::cout << "0b"; + for(size_t i = 0; i < bytes * 8; ++i) { + std::cout << ((value >> (bytes * 8 - i - 1)) & 1); + if (i != (bytes * 8 - 1) && (i % 4 == 3) && i != 0) + std::cout << '\''; + else if (i == bytes * 8 - 1) + std::cout << '\n'; + } + } } From 9d3ad6aa56d8e77cd43bdee0e15d9d6cf3d343c9 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 28 Nov 2025 23:27:01 +0500 Subject: [PATCH 04/23] add solution: add check_flags task --- 01_week/tasks/check_flags/check_flags.cpp | 64 ++++++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/01_week/tasks/check_flags/check_flags.cpp b/01_week/tasks/check_flags/check_flags.cpp index 75e7c652..3eefd815 100644 --- a/01_week/tasks/check_flags/check_flags.cpp +++ b/01_week/tasks/check_flags/check_flags.cpp @@ -1,18 +1,66 @@ #include #include +#include enum class CheckFlags : uint8_t { - NONE = 0, - TIME = (1 << 0), - DATE = (1 << 1), - USER = (1 << 2), - CERT = (1 << 3), - KEYS = (1 << 4), - DEST = (1 << 5), + NONE = 0, //0 + TIME = (1 << 0), //1 + DATE = (1 << 1), //2 + USER = (1 << 2), //4 + CERT = (1 << 3), //8 + KEYS = (1 << 4), //16 + DEST = (1 << 5), //32 ALL = TIME | DATE | USER | CERT | KEYS | DEST }; void PrintCheckFlags(CheckFlags flags) { - throw std::runtime_error{"Not implemented"}; + if (flags <= CheckFlags::ALL && flags >= CheckFlags::NONE){ + std::cout << "["; + bool prev_print = 0; + if (static_cast(flags) & static_cast(CheckFlags::TIME)){ + if (prev_print == 1){ + std::cout << ","; + } + std::cout << "TIME"; + prev_print = 1; + } + if (static_cast(flags) & static_cast(CheckFlags::DATE)){ + if (prev_print == 1){ + std::cout << ","; + } + std::cout << "DATE"; + prev_print = 1; + } + if (static_cast(flags) & static_cast(CheckFlags::USER)){ + if (prev_print == 1){ + std::cout << ","; + } + std::cout << "USER"; + prev_print = 1; + } + if (static_cast(flags) & static_cast(CheckFlags::CERT)){ + if (prev_print == 1){ + std::cout << ","; + } + std::cout << "CERT"; + prev_print = 1; + } + if (static_cast(flags) & static_cast(CheckFlags::KEYS)){ + if (prev_print == 1){ + std::cout << ","; + } + std::cout << "KEYS"; + prev_print = 1; + } + if (static_cast(flags) & static_cast(CheckFlags::DEST)){ + if (prev_print == 1){ + std::cout << ","; + } + std::cout << "DEST"; + prev_print = 1; + } + std::cout << "]"; + } + } From 717cd0fb951282c1bcbfdbdd749540f98fd541a6 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 28 Nov 2025 23:55:06 +0500 Subject: [PATCH 05/23] add solution: add length_lit task --- 01_week/tasks/length_lit/length_lit.cpp | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/01_week/tasks/length_lit/length_lit.cpp b/01_week/tasks/length_lit/length_lit.cpp index e69de29b..6f87a4ee 100644 --- a/01_week/tasks/length_lit/length_lit.cpp +++ b/01_week/tasks/length_lit/length_lit.cpp @@ -0,0 +1,41 @@ +double operator""_cm_to_m(long double x) { + return x / 100.0; +} +double operator""_m_to_cm(long double x) { + return x* 100.0; +} + +double operator""_in_to_ft(long double x) { + return x / 12.0; +} +double operator""_ft_to_in(long double x) { + return x * 12.0; +} + +double operator""_m_to_ft(long double x) { + return x / 0.3048; +} +double operator""_ft_to_m(long double x) { + return x * 0.3048; +} + +double operator""_cm_to_ft(long double x) { + return x / 30.48; +} +double operator""_ft_to_cm(long double x) { + return x * 30.48; +} + +double operator""_cm_to_in(long double x) { + return x / 30.48 * 12.0; +} + +double operator""_m_to_in(long double x) { + return x* 100.0 / 30.48 * 12.0; +} +double operator""_in_to_cm(long double x) { + return x / 12.0 * 30.48; +} +double operator""_in_to_m(long double x) { + return x / 12.0 * 30.48 / 100; +} \ No newline at end of file From c0bd5f402b152f1ac8a7c9b67c3cbea7d7683a00 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Tue, 9 Dec 2025 21:58:59 +0500 Subject: [PATCH 06/23] add solution: add swap_ptr task --- 02_week/tasks/swap_ptr/swap_ptr.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/02_week/tasks/swap_ptr/swap_ptr.cpp b/02_week/tasks/swap_ptr/swap_ptr.cpp index 93db625d..89e48d28 100644 --- a/02_week/tasks/swap_ptr/swap_ptr.cpp +++ b/02_week/tasks/swap_ptr/swap_ptr.cpp @@ -1,6 +1,19 @@ #include -void SwapPtr(/* write arguments here */) { - throw std::runtime_error{"Not implemented"}; -} \ No newline at end of file +void SwapPtr(int*& ptr1, int*& ptr2) { + int* ptr0 = ptr1; + ptr1 = ptr2; + ptr2 = ptr0; +} +void SwapPtr(const int*& ptr1, const int*& ptr2) { + const int* ptr0 = ptr1; + ptr1 = ptr2; + ptr2 = ptr0; +} +void SwapPtr(int**& ptr1, int**& ptr2) { + int** ptr0 = ptr1; + ptr1 = ptr2; + ptr2 = ptr0; +} + From 4eefb344bc0a2cc681ba348a8ad15bae52f644e9 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Tue, 9 Dec 2025 22:16:05 +0500 Subject: [PATCH 07/23] add solution: add func_array task --- 02_week/tasks/func_array/func_array.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/02_week/tasks/func_array/func_array.cpp b/02_week/tasks/func_array/func_array.cpp index b327e68d..aacf084c 100644 --- a/02_week/tasks/func_array/func_array.cpp +++ b/02_week/tasks/func_array/func_array.cpp @@ -1,6 +1,15 @@ #include -double ApplyOperations(double a, double b /* other arguments */) { - throw std::runtime_error{"Not implemented"}; +double ApplyOperations(double a, double b, double (**arr_func)(double, double), size_t size) { + double result = 0; + if (size == 0 or arr_func == nullptr){ + return 0.0; + } + for (size_t i = 0; i < size; ++i){ + if (arr_func[i] != nullptr){ + result += arr_func[i](a, b); + } + } + return result; } \ No newline at end of file From cb169138f3266cf6e4a0b2a2f2ca1f8d32c45703 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Tue, 9 Dec 2025 23:10:34 +0500 Subject: [PATCH 08/23] add solution: add longest task --- 02_week/tasks/longest/longest.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/02_week/tasks/longest/longest.cpp b/02_week/tasks/longest/longest.cpp index 04b3c354..6c9f945a 100644 --- a/02_week/tasks/longest/longest.cpp +++ b/02_week/tasks/longest/longest.cpp @@ -1,6 +1,30 @@ #include -/* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) { - throw std::runtime_error{"Not implemented"}; +char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) { + count = 0; + if ((begin >= end) or (begin == nullptr) or (end == nullptr)){ + return nullptr; + } + char* long_begin = const_cast(begin); + //char long_char = *begin; + size_t len = 0; + char* char0 = const_cast(begin); + while (begin <= end){ + if(*char0 == *begin){ + len++; + } + else{ + if (len > count){ + count = len; + //long_char = char0; + long_begin = const_cast(char0); + } + char0 = const_cast(begin); + len = 1; + } + + begin++; + } + return long_begin; } From 137ed90dfa58c0873f8ba04a5c3e2ea3455b03c8 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Tue, 9 Dec 2025 23:31:18 +0500 Subject: [PATCH 09/23] add solution: add last_of_us task --- 02_week/tasks/last_of_us/last_of_us.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/02_week/tasks/last_of_us/last_of_us.cpp b/02_week/tasks/last_of_us/last_of_us.cpp index c7bf1a25..adf66a98 100644 --- a/02_week/tasks/last_of_us/last_of_us.cpp +++ b/02_week/tasks/last_of_us/last_of_us.cpp @@ -1,6 +1,17 @@ #include -/* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { - throw std::runtime_error{"Not implemented"}; +int* FindLastElement(const int* begin, const int* end, bool (*predicate) (int)) { + if (begin == nullptr or end == nullptr or begin >= end){ + return const_cast(end); + } + int* result = const_cast(end); + int* p = const_cast(begin); + while (p < end){ + if(predicate(*p)){ + result = p; + } + p++; + } + return result; } \ No newline at end of file From 67365364f790bf59a90b97c7f4106d9c41944ac1 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Tue, 9 Dec 2025 23:58:43 +0500 Subject: [PATCH 10/23] add solution: add pretty_array task --- 02_week/tasks/pretty_array/pretty_array.cpp | 48 ++++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/02_week/tasks/pretty_array/pretty_array.cpp b/02_week/tasks/pretty_array/pretty_array.cpp index 48eab341..8d9e4fee 100644 --- a/02_week/tasks/pretty_array/pretty_array.cpp +++ b/02_week/tasks/pretty_array/pretty_array.cpp @@ -1,6 +1,50 @@ #include +#include -void PrintArray(/* write arguments here */) { - throw std::runtime_error{"Not implemented"}; + +void PrintArray(const int* begin, const int* end, size_t ogr = 0) { + /*if (begin == nullptr or end == nullptr){ + return; + }*/ + + size_t i_ogr = 1; + std::cout <<"["; + + if (end >= begin){ + int* p = const_cast(begin); + while (p < end){ + std::cout << *p; + if (p + 1 != end){ + std::cout <<", "; + if (ogr != 0 and i_ogr == ogr){ + std::cout << "..." << std::endl << " "; + i_ogr = 0; + } + } + + p++; + i_ogr++; + } + } + else{ + int* p = const_cast(end); + p--; + while (p >= begin){ + std::cout << *p; + if (p != begin){ + std::cout <<", "; + if (ogr != 0 and i_ogr == ogr){ + std::cout << "..." << std::endl << " "; + i_ogr = 0; + } + } + + p--; + i_ogr++; + } + } + + + std::cout << "]" << std::endl; } \ No newline at end of file From 8d44aa39713a5faba4c2e89f9a1342cf98dbe238 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 16:50:34 +0500 Subject: [PATCH 11/23] add solution: add data_stats task --- 03_week/tasks/data_stats/data_stats.cpp | 23 +++++++++++++++++++++-- 04_week/CMakeLists.txt | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/03_week/tasks/data_stats/data_stats.cpp b/03_week/tasks/data_stats/data_stats.cpp index b941c211..dc13befb 100644 --- a/03_week/tasks/data_stats/data_stats.cpp +++ b/03_week/tasks/data_stats/data_stats.cpp @@ -1,4 +1,6 @@ +#include #include +#include struct DataStats { @@ -6,6 +8,23 @@ struct DataStats { double sd = 0.0; }; -/* return_type */ CalculateDataStats(/* args */) { - throw std::runtime_error{"Not implemented"}; +DataStats CalculateDataStats(std::vector vect) { + int n = 0; + + DataStats rezult = {0, 0}; + if (vect.begin() == vect.end()){ + return rezult; + } + for (auto it = vect.begin(); it != vect.end(); ++it) { + ++n; + rezult.avg += *it; + } + rezult.avg /= n; + for (auto it = vect.begin(); it != vect.end(); ++it) { + rezult.sd += pow((*it - rezult.avg), 2); + } + rezult.sd /= n; + rezult.sd = sqrt(rezult.sd); + return rezult; + } diff --git a/04_week/CMakeLists.txt b/04_week/CMakeLists.txt index 0531237e..97b68f15 100644 --- a/04_week/CMakeLists.txt +++ b/04_week/CMakeLists.txt @@ -7,9 +7,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Гарантирует использов set(EXAMPLES_DIR examples) # Определим переменную с именем директории set(TASKS_DIR tasks) -add_subdirectory(tasks) +# add_subdirectory(tasks) # Создать исполняемый файл для каждого примера if (BUILD_EXAMPLES_04_WEEK) # add_example(struct_examples ${EXAMPLES_DIR}/struct_examples.cpp) -endif() \ No newline at end of file +endif() From a1d5e06b5010d13f3ffd31e8d6d0078c0ba4d4c2 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 22:18:26 +0500 Subject: [PATCH 12/23] add solution: add unique task --- 03_week/tasks/unique/unique.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/03_week/tasks/unique/unique.cpp b/03_week/tasks/unique/unique.cpp index 9d2545bb..94e8adac 100644 --- a/03_week/tasks/unique/unique.cpp +++ b/03_week/tasks/unique/unique.cpp @@ -1,6 +1,25 @@ #include #include -/* return_type */ Unique(/* args */) { - throw std::runtime_error{"Not implemented"}; +std::vector Unique(std::vector vec_in) { + size_t size_in = size(vec_in); + std::vector vec_out; + vec_out.reserve(size_in); + for (auto elem : vec_in) { + bool elem_in_in = false; + for (auto elem_out : vec_out){ + if (elem_out == elem){ + elem_in_in = true; + break; + } + else if (elem_out > elem){ + break; + } + } + if (elem_in_in == false){ + vec_out.push_back(elem); + } + } + vec_out.shrink_to_fit(); + return vec_out; } From 4f3455994a3b09d4e76cefe7b0764e2cf0566ff3 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 22:38:54 +0500 Subject: [PATCH 13/23] add solution: add range task --- 03_week/tasks/range/range.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/03_week/tasks/range/range.cpp b/03_week/tasks/range/range.cpp index d2085495..5a43b474 100644 --- a/03_week/tasks/range/range.cpp +++ b/03_week/tasks/range/range.cpp @@ -2,6 +2,15 @@ #include -std::vector Range(int from, int to, int step) { - throw std::runtime_error{"Not implemented"}; +std::vector Range(int from, int to, int step = 1) { + std::vector range; + if ((to - from) * step <= 0){ + return range; + } + + range.reserve(abs(to - from) / abs(step) + abs(to - from) % abs(step)); + for (int i = from; (to - i) * step > 0; i += step){ + range.push_back(i); + } + return range; } From 7d78143d71e52eb67cb9354c53d09f45b37fb03e Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 23:18:51 +0500 Subject: [PATCH 14/23] add solution: add minmax task --- 03_week/tasks/minmax/minmax.cpp | 49 +++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/minmax/minmax.cpp b/03_week/tasks/minmax/minmax.cpp index c2869799..5d070749 100644 --- a/03_week/tasks/minmax/minmax.cpp +++ b/03_week/tasks/minmax/minmax.cpp @@ -1,6 +1,49 @@ #include +#include +#include - -/* return_type */ MinMax(/* args */) { - throw std::runtime_error{"Not implemented"}; +std::pair ::iterator, std::vector::iterator> MinMax(std::vector& vec) { + std::pair::iterator, std::vector::iterator> rez; + if (vec.begin() == vec.end()){ + rez.first = vec.begin(); + rez.second = vec.begin(); + return rez; + } + auto min_it = vec.begin(); + auto max_it = vec.begin(); + for (auto it = vec.begin(); it != vec.end(); ++it) { + if (*it < *min_it){ + min_it = it; + } + if (*it >= *max_it){ + max_it = it; + } + } + + rez.first = min_it; + rez.second = max_it; + return rez; } + +std::pair ::const_iterator, std::vector::const_iterator> MinMax(const std::vector& vec) { + std::pair::const_iterator, std::vector::const_iterator> rez; + if (vec.begin() == vec.end()){ + rez.first = vec.begin(); + rez.second = vec.begin(); + return rez; + } + auto min_it = vec.begin(); + auto max_it = vec.begin(); + for (auto it = vec.begin(); it != vec.end(); ++it) { + if (*it < *min_it){ + min_it = it; + } + if (*it >= *max_it){ + max_it = it; + } + } + + rez.first = min_it; + rez.second = max_it; + return rez; +} \ No newline at end of file From 26cca116a978bfefd96500fc62751ede0ee2986c Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 23:22:28 +0500 Subject: [PATCH 15/23] edit unique task --- 03_week/tasks/unique/unique.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/03_week/tasks/unique/unique.cpp b/03_week/tasks/unique/unique.cpp index 94e8adac..4d5be3be 100644 --- a/03_week/tasks/unique/unique.cpp +++ b/03_week/tasks/unique/unique.cpp @@ -1,7 +1,7 @@ #include #include -std::vector Unique(std::vector vec_in) { +std::vector Unique(std::vector& vec_in) { size_t size_in = size(vec_in); std::vector vec_out; vec_out.reserve(size_in); @@ -23,3 +23,26 @@ std::vector Unique(std::vector vec_in) { vec_out.shrink_to_fit(); return vec_out; } + +const std::vector Unique(const std::vector& vec_in) { + size_t size_in = size(vec_in); + std::vector vec_out; + vec_out.reserve(size_in); + for (auto elem : vec_in) { + bool elem_in_in = false; + for (auto elem_out : vec_out){ + if (elem_out == elem){ + elem_in_in = true; + break; + } + else if (elem_out > elem){ + break; + } + } + if (elem_in_in == false){ + vec_out.push_back(elem); + } + } + vec_out.shrink_to_fit(); + return vec_out; +} \ No newline at end of file From 71022cd8334cd87a5c438ef7d7759c4b70c4434f Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 23:24:14 +0500 Subject: [PATCH 16/23] edit data_stats task --- 03_week/tasks/data_stats/data_stats.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/03_week/tasks/data_stats/data_stats.cpp b/03_week/tasks/data_stats/data_stats.cpp index dc13befb..0efa2b78 100644 --- a/03_week/tasks/data_stats/data_stats.cpp +++ b/03_week/tasks/data_stats/data_stats.cpp @@ -8,7 +8,7 @@ struct DataStats { double sd = 0.0; }; -DataStats CalculateDataStats(std::vector vect) { +DataStats CalculateDataStats(std::vector& vect) { int n = 0; DataStats rezult = {0, 0}; @@ -26,5 +26,24 @@ DataStats CalculateDataStats(std::vector vect) { rezult.sd /= n; rezult.sd = sqrt(rezult.sd); return rezult; +} +DataStats CalculateDataStats(const std::vector& vect) { + int n = 0; + + DataStats rezult = {0, 0}; + if (vect.begin() == vect.end()){ + return rezult; + } + for (auto it = vect.begin(); it != vect.end(); ++it) { + ++n; + rezult.avg += *it; + } + rezult.avg /= n; + for (auto it = vect.begin(); it != vect.end(); ++it) { + rezult.sd += pow((*it - rezult.avg), 2); + } + rezult.sd /= n; + rezult.sd = sqrt(rezult.sd); + return rezult; } From 3b7f11e1983ce91795b2fd7d1d7826b2ae34a55f Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Thu, 18 Dec 2025 23:33:07 +0500 Subject: [PATCH 17/23] edit CMakeLists.txt --- 04_week/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/04_week/CMakeLists.txt b/04_week/CMakeLists.txt index ed77b131..ff9cd88d 100644 --- a/04_week/CMakeLists.txt +++ b/04_week/CMakeLists.txt @@ -11,10 +11,5 @@ add_subdirectory(tasks) # Создать исполняемый файл для каждого примера if (BUILD_EXAMPLES_04_WEEK) -<<<<<<< HEAD -# add_example(struct_examples ${EXAMPLES_DIR}/struct_examples.cpp) -endif() -======= # add_example(class_examples ${EXAMPLES_DIR}/class_examples.cpp) endif() ->>>>>>> 2eafd557ce1d36fb50e5e9b2cf92b64841d54edc From d3c79721acefe4e69be63355ae11baf407c99f6d Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 19 Dec 2025 20:49:54 +0500 Subject: [PATCH 18/23] add solution: add find_all task --- 03_week/tasks/find_all/find_all.cpp | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/find_all/find_all.cpp b/03_week/tasks/find_all/find_all.cpp index 74f393b2..b030532a 100644 --- a/03_week/tasks/find_all/find_all.cpp +++ b/03_week/tasks/find_all/find_all.cpp @@ -1,6 +1,35 @@ #include +#include -/* return_type */ FindAll(/* args */) { - throw std::runtime_error{"Not implemented"}; -} \ No newline at end of file +std::vector FindAll(std::vector& vec, bool (*func) (int)) { + std::vector vec_out; + if (vec.empty() or func == nullptr){ + return vec_out; + } + vec_out.reserve(size(vec)); + size_t size_vec = size(vec); + for (size_t i = 0; i < size_vec; ++i) { + if (func(vec[i])){ + vec_out.push_back(i); + } + } + vec_out.shrink_to_fit(); + return vec_out; +} + +const std::vector FindAll(const std::vector& vec, bool (*func) (int)) { + std::vector vec_out; + if (vec.empty() or func == nullptr){ + return vec_out; + } + vec_out.reserve(size(vec)); + size_t size_vec = size(vec); + for (size_t i = 0; i < size_vec; ++i) { + if (func(vec[i])){ + vec_out.push_back(i); + } + } + vec_out.shrink_to_fit(); + return vec_out; +} From d113d109b094da102e1a10f3fac5dbe322970e23 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Fri, 19 Dec 2025 22:21:19 +0500 Subject: [PATCH 19/23] add solution: add os_overload task --- 03_week/tasks/os_overload/os_overload.cpp | 101 ++++++++++++++++++++-- 1 file changed, 96 insertions(+), 5 deletions(-) diff --git a/03_week/tasks/os_overload/os_overload.cpp b/03_week/tasks/os_overload/os_overload.cpp index e473418d..3a59e6ed 100644 --- a/03_week/tasks/os_overload/os_overload.cpp +++ b/03_week/tasks/os_overload/os_overload.cpp @@ -1,21 +1,112 @@ #include #include #include +#include struct Coord2D { - int x; - int y; + int x = 0; + int y = 0; }; struct Circle { Coord2D coord; - unsigned radius; + unsigned radius = 1; }; using CircleRegion = std::pair; using CircleRegionList = std::vector; -/* return_type */ operator<<(/* args */) { - throw std::runtime_error{"Not implemented"}; +std::ostream& operator<<(std::ostream& os, Coord2D& coord) { + os << "("<< coord.x << ", " << coord.y << ")"; + return os; } + +std::ostream& operator<<(std::ostream& os, Circle& circle) { + os << "circle["; + if (circle.radius != 0){ + os << circle.coord << ", r = " << circle.radius; + } + os << "]"; + return os; +} + +std::ostream& operator<<(std::ostream& os, CircleRegion& region) { + if (region.second){ + os << "+"; + } + else{ + os << "-"; + } + if (region.first.radius != 0){ + os << region.first; + } + else{ + os << "circle[]"; + } + return os; +} + +std::ostream& operator<<(std::ostream& os, CircleRegionList& list) { + size_t size_list = size(list); + os << "{"; + if (size_list != 0){ + os << std::endl; + } + for (size_t i = 0; i < size_list; ++i) { + os << '\t' << list[i]; + if (i != (size_list - 1)){ + os << ","; + } + os << std::endl; + } + os << "}"; + return os; +} + +std::ostream& operator<<(std::ostream& os, const Coord2D& coord) { + os << "("<< coord.x << ", " << coord.y << ")"; + return os; +} + +std::ostream& operator<<(std::ostream& os, const Circle& circle) { + os << "circle["; + if (circle.radius != 0){ + os << circle.coord << ", r = " << circle.radius; + } + os << "]"; + return os; +} + +std::ostream& operator<<(std::ostream& os, const CircleRegion& region) { + if (region.second){ + os << "+"; + } + else{ + os << "-"; + } + if (region.first.radius != 0){ + os << region.first; + } + else{ + os << "circle[]"; + } + return os; +} + +std::ostream& operator<<(std::ostream& os, const CircleRegionList& list) { + size_t size_list = size(list); + os << "{"; + if (size_list != 0){ + os << std::endl; + } + for (size_t i = 0; i < size_list; ++i) { + os << '\t' << list[i]; + if (i != (size_list - 1)){ + os << ","; + } + os << std::endl; + } + os << "}"; + return os; +} \ No newline at end of file From f138cee88f7c1f2bab1ebd6a40b02a86067fcc4e Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Sat, 20 Dec 2025 00:34:16 +0500 Subject: [PATCH 20/23] add solution: add easy_compare task --- 03_week/tasks/easy_compare/easy_compare.cpp | 66 +++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/03_week/tasks/easy_compare/easy_compare.cpp b/03_week/tasks/easy_compare/easy_compare.cpp index dd5cb7f6..c7bd590a 100644 --- a/03_week/tasks/easy_compare/easy_compare.cpp +++ b/03_week/tasks/easy_compare/easy_compare.cpp @@ -2,9 +2,9 @@ struct Date { - unsigned year; - unsigned month; - unsigned day; + unsigned year = 0u; + unsigned month = 0u; + unsigned day = 0u; }; struct StudentInfo { @@ -13,4 +13,62 @@ struct StudentInfo { int score; unsigned course; Date birth_date; -}; \ No newline at end of file +}; + +bool operator<(Date date1, Date date2) { + return std::tie(date1.year, date1.month, date1.day) + < std::tie(date2.year, date2.month, date2.day); +} + +bool operator==(Date date1, Date date2) { + return std::tie(date1.year, date1.month, date1.day) + == std::tie(date2.year, date2.month, date2.day); +} + +bool operator>(Date date1, Date date2) { + return !(date1 < date2) and !(date1 == date2); +} +bool operator>=(Date date1, Date date2) { + return !(date1 < date2) or (date1 == date2); +} +bool operator<=(Date date1, Date date2) { + return (date1 < date2) or (date1 == date2); +} +bool operator!=(Date date1, Date date2) { + return !(date1 == date2); +} + +bool operator==(StudentInfo st1, StudentInfo st2) { + return std::tie(st1.mark, st1.score) == std::tie(st2.mark, st2.score); +} +bool operator!=(StudentInfo st1, StudentInfo st2) { + return !(std::tie(st1.mark, st1.score) == std::tie(st2.mark, st2.score)); +} + +bool operator<(StudentInfo st1, StudentInfo st2) { + + if (st1.mark != st2.mark) { + return st1.mark > st2.mark; + } + if (st1.score != st2.score) { + return st1.score < st2.score; + } + if (st1.course != st2.course) { + return st1.course > st2.course; + } + if (st1.birth_date != st2.birth_date) { + return st1.birth_date < st2.birth_date; + } + else + return false; + +} +bool operator>(StudentInfo st1, StudentInfo st2) { + return !(st1 < st2) and !(st1 == st2); +} +bool operator>=(StudentInfo st1, StudentInfo st2) { + return !(st1 < st2) or (st1 == st2); +} +bool operator<=(StudentInfo st1, StudentInfo st2) { + return (st1 < st2) or (st1 == st2); +} \ No newline at end of file From f971b6d1fa6702d389da2b687ceb0bbc33dc3cc9 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Sat, 20 Dec 2025 01:22:28 +0500 Subject: [PATCH 21/23] add solution: add filter task --- 03_week/tasks/filter/filter.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/filter/filter.cpp b/03_week/tasks/filter/filter.cpp index 6648cb39..ffa82067 100644 --- a/03_week/tasks/filter/filter.cpp +++ b/03_week/tasks/filter/filter.cpp @@ -1,6 +1,21 @@ #include +#include -/* return_type */ Filter(/* args */) { - throw std::runtime_error{"Not implemented"}; -} \ No newline at end of file +std::vector Filter(std::vector& vec, bool (*func) (int)) { + if (vec.empty() or func == nullptr){ + return vec; + } + auto it_rez = vec.begin(); + size_t len = 0; + for (auto it = vec.begin(); it != vec.end(); ++it) { + if (func(*it)){ + *it_rez = *it; + it_rez += 1; + len += 1; + } + } + vec.resize(len); + return vec; +} + From 0a562d028defbb498ef8a23d97c493be0fcea66e Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Sat, 27 Dec 2025 00:43:01 +0500 Subject: [PATCH 22/23] add solution: add stack task --- 04_week/tasks/stack/stack.cpp | 62 ++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/04_week/tasks/stack/stack.cpp b/04_week/tasks/stack/stack.cpp index 222e4ffc..c46733d6 100644 --- a/04_week/tasks/stack/stack.cpp +++ b/04_week/tasks/stack/stack.cpp @@ -2,5 +2,65 @@ class Stack { - + public: + void Push(int value); + bool Pop(); + int& Top(); + const int& Top() const; + bool Empty() const; + size_t Size() const; + void Clear(); + void Swap(Stack& other); + bool operator==(const Stack& other) const; + bool operator!=(const Stack& other) const; + private: + std::vector vec; }; + + +void Stack::Push(int value) { + vec.push_back(value); +} +bool Stack::Pop() { + if (vec.empty()) { + return false; + } + vec.pop_back(); + return true; +} + +bool Stack::Empty() const { + return vec.empty(); +} + +int& Stack::Top(){ + return vec.back(); +} + +const int& Stack::Top() const { + return vec.back(); +} + + + +size_t Stack::Size() const{ + return vec.size(); +} + +void Stack::Clear() { + vec.clear(); +} + +void Stack::Swap(Stack& other) { + vec.swap(other.vec); +} + +bool Stack::operator==(const Stack& other) const { + return vec == other.vec; +} +bool Stack::operator!=(const Stack& other) const { + return !(*this == other); +} + + + From 53346cf5deb1bd1277789a851401fa620eea46e0 Mon Sep 17 00:00:00 2001 From: KaigorodovMM Date: Sat, 27 Dec 2025 01:54:38 +0500 Subject: [PATCH 23/23] add solution: add queue task --- 04_week/tasks/queue/queue.cpp | 119 ++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/04_week/tasks/queue/queue.cpp b/04_week/tasks/queue/queue.cpp index 2a9f8493..9355b6fa 100644 --- a/04_week/tasks/queue/queue.cpp +++ b/04_week/tasks/queue/queue.cpp @@ -1,6 +1,125 @@ #include +#include class Queue { + public: + Queue() = default; + Queue(std::vector& vec); + Queue(std::stack& s); + Queue(std::initializer_list init_list); + Queue(size_t size); + void Push(int value); + bool Pop(); + int& Front(); + int& Back(); + const int& Front() const; + const int& Back() const; + bool Empty() const; + size_t Size() const; + void Clear(); + void Swap(Queue& other); + + bool operator==(const Queue& other) const; + bool operator!=(const Queue& other) const; + + private: + std::vector vec_in; + std::vector vec_out; }; +Queue::Queue(std::vector& vec) { + for (auto it : vec) { + vec_out.push_back(it); + } +} +Queue::Queue(std::stack& s) { + std::stack st = s; + std::vector vec; + while (!st.empty()) { + vec_out.push_back(st.top()); + st.pop(); + } +} +Queue::Queue(std::initializer_list init_list) { + for (auto it : init_list) { + vec_in.push_back(it); + } +} + +Queue::Queue(size_t size) { + vec_in.reserve(size); + vec_out.reserve(size); +} + +void Queue::Push(int value) { + vec_in.push_back(value); +} +bool Queue::Pop() { + if (vec_out.empty()) { + while (!vec_in.empty()) { + vec_out.push_back(vec_in.back()); + vec_in.pop_back(); + } + } + if (vec_out.empty()) { + return false; + } + vec_out.pop_back(); + return true; +} + +int& Queue::Back() { + if (!vec_in.empty()){ + return vec_in.back(); + } + return vec_out.front(); + +} +int& Queue::Front() { + if (vec_out.empty()) { + return vec_in.back(); + } + return vec_out.back(); +} + +const int& Queue::Back() const{ + if (!vec_in.empty()){ + return vec_in.back(); + } + return vec_out.front(); + +} +const int& Queue::Front() const{ + if (vec_out.empty()) { + return vec_in.back(); + } + return vec_out.back(); +} + +bool Queue::Empty() const { + return vec_in.empty() && vec_out.empty(); +} + +size_t Queue::Size() const{ + return vec_in.size() + vec_out.size(); +} + +void Queue::Clear() { + vec_in.clear(); + vec_out.clear(); +} + +void Queue::Swap(Queue& other) { + vec_in.swap(other.vec_in); + vec_out.swap(other.vec_out); +} + +bool Queue::operator==(const Queue& other_queue) const { + return other_queue.vec_in == vec_in && other_queue.vec_out == vec_out; +} + +bool Queue::operator!=(const Queue& other_queue) const { + return !(*this == other_queue); +} +