From 786c58723ef4c0fe7948c6db5e6fab7a2e19da73 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sat, 22 Nov 2025 22:49:53 +0500 Subject: [PATCH 01/21] add solution: addition, rms, print_bits tasks --- 01_week/tasks/addition/addition.cpp | 2 +- 01_week/tasks/print_bits/print_bits.cpp | 22 +++++++++++++++++++++- 01_week/tasks/rms/rms.cpp | 12 ++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/01_week/tasks/addition/addition.cpp b/01_week/tasks/addition/addition.cpp index 92872802..05ffd7d1 100644 --- a/01_week/tasks/addition/addition.cpp +++ b/01_week/tasks/addition/addition.cpp @@ -3,5 +3,5 @@ int64_t Addition(int a, int b) { - throw std::runtime_error{"Not implemented"}; + return static_cast(a) + static_cast(b); } \ No newline at end of file diff --git a/01_week/tasks/print_bits/print_bits.cpp b/01_week/tasks/print_bits/print_bits.cpp index a48a43c1..8dbbc6fa 100644 --- a/01_week/tasks/print_bits/print_bits.cpp +++ b/01_week/tasks/print_bits/print_bits.cpp @@ -1,7 +1,27 @@ #include #include +#include void PrintBits(long long value, size_t bytes) { - throw std::runtime_error{"Not implemented"}; + using std::cout; + // Проверка корректности размера + if (bytes == 0 || bytes > 8) { + return; + } + std::cout << "0b"; + + // Проходим по всем битам, начиная со старшего + for (size_t pos = bytes * 8; pos > 0; --pos) { + // Получаем значение бита на текущей позиции + int bit = (value >> (pos - 1)) & 1; + std::cout << bit; + + // Добавляем апостроф между байтами (после каждых 4 бит, кроме последней группы) + if ((pos - 1) > 0 && (pos - 1) % 4 == 0) { + std::cout << "'"; + } + } + + std::cout << "\n"; } diff --git a/01_week/tasks/rms/rms.cpp b/01_week/tasks/rms/rms.cpp index 6882f0a9..06782da0 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 square_sum = 0.0; + for(size_t i = 0; i < size; ++i) { + square_sum += values[i] * values[i]; + } + return sqrt(square_sum/size); } \ No newline at end of file From 2be84bb3995561f099837fe471bf97419a37a2d2 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 23 Nov 2025 21:58:25 +0500 Subject: [PATCH 02/21] add (solution): add check_flags task --- 01_week/tasks/check_flags/check_flags.cpp | 38 ++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/01_week/tasks/check_flags/check_flags.cpp b/01_week/tasks/check_flags/check_flags.cpp index 75e7c652..340c1c97 100644 --- a/01_week/tasks/check_flags/check_flags.cpp +++ b/01_week/tasks/check_flags/check_flags.cpp @@ -1,5 +1,6 @@ #include #include +#include enum class CheckFlags : uint8_t { @@ -14,5 +15,40 @@ enum class CheckFlags : uint8_t { }; void PrintCheckFlags(CheckFlags flags) { - throw std::runtime_error{"Not implemented"}; + // Значение находится в допустимом диапазоне + uint8_t value = static_cast(flags); + if (value == 0) { + std::cout << "[]"; + return; + } + if (value > static_cast(CheckFlags::ALL)) { + return; + } + // Последнее значение + if (value == static_cast(CheckFlags::ALL)) { + std::cout << "[TIME,DATE,USER,CERT,KEYS,DEST]"; + return; + } + + std::cout << "["; + bool first = true; + + const std::pair flag_names[] = { + {CheckFlags::TIME, "TIME"}, + {CheckFlags::DATE, "DATE"}, + {CheckFlags::USER, "USER"}, + {CheckFlags::CERT, "CERT"}, + {CheckFlags::KEYS, "KEYS"}, + {CheckFlags::DEST, "DEST"} + }; + + for (const auto& [flag, name] : flag_names) { + if (value & static_cast(flag)) { + if (!first) std::cout << ","; + std::cout << name; + first = false; + } + } + + std::cout << "]"; } From 73ae72530634f5bca4e753ffb1f9cd68af65d081 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 23 Nov 2025 22:41:50 +0500 Subject: [PATCH 03/21] add (solution) add quadratic tast --- 01_week/tasks/quadratic/quadratic.cpp | 52 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/01_week/tasks/quadratic/quadratic.cpp b/01_week/tasks/quadratic/quadratic.cpp index abf7d632..6e3c300c 100644 --- a/01_week/tasks/quadratic/quadratic.cpp +++ b/01_week/tasks/quadratic/quadratic.cpp @@ -1,6 +1,56 @@ #include +#include +#include +#include +void PrintRoot(double x) { + // Для избавления от заведомо небольших значений + if (std::abs(x) < 1e-10) { + x = 0.0; + } + std::cout << std::setprecision(6) << x; +} void SolveQuadratic(int a, int b, int c) { - throw std::runtime_error{"Not implemented"}; + if(a == 0 && b == 0 && c == 0) { + std::cout << "infinite solutions"; + return; + } + + double a_ = static_cast(a); + double b_ = static_cast(b); + double c_ = static_cast(c); + + if(a_ == 0) { + if(b_ == 0) { + // Нет решений + std::cout << "no solutions"; + } else { + // Один корень линейного уравнения + PrintRoot(-c_ / b_); + } + return; + } + + double D = b_*b_ - 4*a_*c_; + if (D > 0) { + double sqrt_d = std::sqrt(D); + double x1 = (-b_ - sqrt_d) / (2.0 * a_); + double x2 = (-b_ + sqrt_d) / (2.0 * a_); + + // Гарантируем, что x1 < x2 + if (x1 > x2) { + std::swap(x1, x2); + } + PrintRoot(x1); + std::cout << " "; + PrintRoot(x2); + } + else if (D == 0) { + double x = -b_ / (2.0 * a_); + PrintRoot(x); + } + else { + std::cout << "no solutions"; + } } \ No newline at end of file From 3c312a5eb5277a9ee2e91a36c4d2873b8c0f4099 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Mon, 24 Nov 2025 22:58:55 +0500 Subject: [PATCH 04/21] add solution: add length_lit task --- 01_week/tasks/length_lit/length_lit.cpp | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/01_week/tasks/length_lit/length_lit.cpp b/01_week/tasks/length_lit/length_lit.cpp index e69de29b..c9e08123 100644 --- a/01_week/tasks/length_lit/length_lit.cpp +++ b/01_week/tasks/length_lit/length_lit.cpp @@ -0,0 +1,55 @@ +double FT_IN_M = 1.0 / 0.3048; +double FT_IN_INCHES = 12.0; +double INCH_IN_CM = 2.54; + +// Футы в другие величины +double operator""_ft_to_m(long double ft) { + return ft / FT_IN_M; +} + +double operator""_ft_to_cm(long double ft) { + return ft / FT_IN_M * 100.0; +} + +double operator""_ft_to_in(long double ft) { + return ft * FT_IN_INCHES; +} + +// Дюймы в другие величины +double operator""_in_to_ft(long double in) { + return in / FT_IN_INCHES; +} + +double operator""_in_to_cm(long double in) { + return in * INCH_IN_CM; +} + +double operator""_in_to_m(long double inches) { + return inches * INCH_IN_CM / 100; +} + +// См в другие величины +double operator""_cm_to_m(long double centimeters) { + return centimeters / 100; +} + +double operator""_cm_to_in(long double centimeters) { + return centimeters / INCH_IN_CM; +} + +double operator""_cm_to_ft(long double centimeters) { + return centimeters / (FT_IN_INCHES * INCH_IN_CM); +} + +// Метры в другие величины +double operator""_m_to_ft(long double meters) { + return meters * 100 / (INCH_IN_CM * FT_IN_INCHES); +} + +double operator""_m_to_in(long double meters) { + return meters * 100 / INCH_IN_CM; +} + +double operator""_m_to_cm(long double meters) { + return meters * 100; +} \ No newline at end of file From b53ca2a4b4b0aeeaa1a91d4446c174330a687676 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Wed, 3 Dec 2025 18:01:47 +0500 Subject: [PATCH 05/21] add [solution]: add task swap_ptr --- 02_week/tasks/swap_ptr/swap_ptr.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/02_week/tasks/swap_ptr/swap_ptr.cpp b/02_week/tasks/swap_ptr/swap_ptr.cpp index 93db625d..ab74aef4 100644 --- a/02_week/tasks/swap_ptr/swap_ptr.cpp +++ b/02_week/tasks/swap_ptr/swap_ptr.cpp @@ -1,6 +1,17 @@ #include -void SwapPtr(/* write arguments here */) { - throw std::runtime_error{"Not implemented"}; +template +void SwapPtr(T*& ptr1, T*& ptr2) { + // Проверяем, указывают ли ptr1 и ptr2 на указатели + if constexpr (std::is_pointer_v>) { + // T* - это указатель на указатель (например: int**) + // Меняем значения, на которые указываем + SwapPtr(*ptr1, *ptr2); // Рекурсивный вызов + } + + // Меняем сами указатели + T* temp = ptr1; + ptr1 = ptr2; + ptr2 = temp; } \ No newline at end of file From 3e5a80a914aa17cf590c32f292b90550a8a6594e Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Wed, 3 Dec 2025 22:45:00 +0500 Subject: [PATCH 06/21] add [solution]: add task func_array --- 02_week/tasks/func_array/func_array.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/02_week/tasks/func_array/func_array.cpp b/02_week/tasks/func_array/func_array.cpp index b327e68d..aa461fe8 100644 --- a/02_week/tasks/func_array/func_array.cpp +++ b/02_week/tasks/func_array/func_array.cpp @@ -1,6 +1,16 @@ -#include -double ApplyOperations(double a, double b /* other arguments */) { - throw std::runtime_error{"Not implemented"}; +double ApplyOperations(double a, double b, double (*ptr[])(double, double), size_t size) { + double sum = 0.0; + + if(size == 0 || ptr == nullptr) { + return sum; + } + + for (size_t i = 0; i < size; ++i) { + if(ptr[i] == nullptr) continue; + sum += ptr[i](a, b); + } + + return sum; } \ No newline at end of file From 9159eebca30513f60545160a1a6ba520b3539977 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Wed, 3 Dec 2025 23:10:50 +0500 Subject: [PATCH 07/21] add [solution]: add task longest --- 02_week/tasks/longest/longest.cpp | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/02_week/tasks/longest/longest.cpp b/02_week/tasks/longest/longest.cpp index 04b3c354..cdb03438 100644 --- a/02_week/tasks/longest/longest.cpp +++ b/02_week/tasks/longest/longest.cpp @@ -1,6 +1,34 @@ #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) { + if (begin == nullptr || end == nullptr || begin >= end) { + count = 0; + return nullptr; + } + + const char* longest_ptr = begin; + const char* current_ptr = begin; + size_t max_count = 1; + size_t current_count = 1; + + for (const char* ptr = begin + 1; ptr < end; ++ptr) { + if (*ptr == *(ptr - 1)) { + current_count++; + } else { + if(current_count > max_count) { + max_count = current_count; + longest_ptr = current_ptr; + } + current_ptr = ptr; + current_count = 1; + } + } + + if(current_count > max_count) { + max_count = current_count; + longest_ptr = current_ptr; + } + count = max_count; + return const_cast(longest_ptr); } From 9f39dfa94cbe1d2b68552f740bde64720a2a25e9 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sat, 6 Dec 2025 22:35:04 +0500 Subject: [PATCH 08/21] add [solution]: add task last_of_us --- 02_week/tasks/last_of_us/last_of_us.cpp | 9 +++++++-- 1 file changed, 7 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..c4290840 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,11 @@ #include -/* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { - throw std::runtime_error{"Not implemented"}; +const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(const int)) { + if((begin > end) || (begin == nullptr) || (end == nullptr)) return end; + + for(const int* ptr = end - 1; ptr >= begin; --ptr) { + if (predicate(*ptr)) {return ptr;} + } + return end; } \ No newline at end of file From 4f481053adc1d4695894cd30edce6dfb90c20ccf Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sat, 6 Dec 2025 23:18:53 +0500 Subject: [PATCH 09/21] add [solution]: add task little_big --- 02_week/tasks/little_big/little_big.cpp | 43 ++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/02_week/tasks/little_big/little_big.cpp b/02_week/tasks/little_big/little_big.cpp index abe24379..799259df 100644 --- a/02_week/tasks/little_big/little_big.cpp +++ b/02_week/tasks/little_big/little_big.cpp @@ -1,10 +1,45 @@ #include +#include +#include +#include -void PrintMemory(int /* write arguments here */) { - throw std::runtime_error{"Not implemented"}; +void PrintMemory(int value, bool reverse = false) { + unsigned char* bytes = reinterpret_cast(&value); + + std::cout << "0x"; + + if (reverse) { + // Вывод в обратном порядке (big-endian) + for (int i = sizeof(int) - 1; i >= 0; --i) { + std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast(bytes[i]); + } + } else { + // Вывод в естественном порядке (little-endian) + for (size_t i = 0; i < sizeof(int); ++i) { + std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast(bytes[i]); + } + } + + std::cout << std::endl; } -void PrintMemory(double /* write arguments here */) { - throw std::runtime_error{"Not implemented"}; +void PrintMemory(double value, bool reverseBytes = false) { + unsigned char* bytes = reinterpret_cast(&value); + + std::cout << "0x"; + + if (reverseBytes) { + // Вывод в обратном порядке (big-endian) + for (int i = sizeof(double) - 1; i >= 0; --i) { + std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast(bytes[i]); + } + } else { + // Вывод в естественном порядке (little-endian) + for (size_t i = 0; i < sizeof(double); ++i) { + std::cout << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast(bytes[i]); + } + } + + std::cout << std::endl; } \ No newline at end of file From b6f99dcc60c0ada124a7f5982d518c330d4f35e3 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 7 Dec 2025 21:04:58 +0500 Subject: [PATCH 10/21] add [solution]: add task pretty_array --- 02_week/tasks/pretty_array/pretty_array.cpp | 38 +++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/02_week/tasks/pretty_array/pretty_array.cpp b/02_week/tasks/pretty_array/pretty_array.cpp index 48eab341..30509eb0 100644 --- a/02_week/tasks/pretty_array/pretty_array.cpp +++ b/02_week/tasks/pretty_array/pretty_array.cpp @@ -1,6 +1,38 @@ #include +#include - -void PrintArray(/* write arguments here */) { - throw std::runtime_error{"Not implemented"}; +void PrintArray(const int* begin, const int* end, int constraint = 0) { + if (begin == end || begin == nullptr || end == nullptr) + { + std::cout << "[]\n"; + return; + } + + int count = 0; + std::cout << "["; + if(begin < end) { + for(const int* ptr = begin; ptr < end; ++ptr) { + if((count == constraint) && (constraint != 0)) { + count = 0; + std::cout << "...\n "; + } + std::cout << *ptr; + if(ptr != end - 1) { std::cout << ", "; } + ++count; + } + std::cout << "]\n"; + } else { + ++end; + for(const int* ptr = begin; ptr >= end; --ptr) { + if((count == constraint) && (constraint != 0)) { + count = 0; + std::cout << "...\n "; + } + std::cout << *ptr; + if(ptr != end) { std::cout << ", "; } + if(ptr == end) { break; } + ++count; + } + std::cout << "]\n"; + } } \ No newline at end of file From e8920e769668c6a9e3ddf6e12cf021772544662b Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 14 Dec 2025 10:28:47 +0500 Subject: [PATCH 11/21] add solution: add task [data_stats] --- 03_week/tasks/data_stats/data_stats.cpp | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/data_stats/data_stats.cpp b/03_week/tasks/data_stats/data_stats.cpp index b941c211..49bbdd56 100644 --- a/03_week/tasks/data_stats/data_stats.cpp +++ b/03_week/tasks/data_stats/data_stats.cpp @@ -1,11 +1,31 @@ #include - +#include +#include struct DataStats { double avg = 0.0; double sd = 0.0; }; -/* return_type */ CalculateDataStats(/* args */) { - throw std::runtime_error{"Not implemented"}; +DataStats CalculateDataStats(std::vector numbers) { + DataStats stats; + + if(numbers.empty()) { + return stats; + } + + for(auto num : numbers) { + stats.avg += num; + stats.sd += static_cast(num) * num; + } + // Вычисляем среднее значение + stats.avg = static_cast(stats.avg) / numbers.size(); + + if (numbers.size() > 1) { + stats.sd = std::sqrt((stats.sd - numbers.size() * stats.avg * stats.avg) / numbers.size()); + } + else { + stats.sd = 0; + } + return stats; } From 56befd70f77a0d4d5e6110ea97284ad4b8cd4d78 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 14 Dec 2025 16:48:22 +0500 Subject: [PATCH 12/21] add solution: add task [unique] --- 03_week/tasks/unique/unique.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/unique/unique.cpp b/03_week/tasks/unique/unique.cpp index 9d2545bb..9161363c 100644 --- a/03_week/tasks/unique/unique.cpp +++ b/03_week/tasks/unique/unique.cpp @@ -1,6 +1,17 @@ #include #include -/* return_type */ Unique(/* args */) { - throw std::runtime_error{"Not implemented"}; -} +std::vector Unique(std::vector sorted_nums) { + std::vector unique_nums; + if(sorted_nums.empty()) {return unique_nums;} + int previous = *(sorted_nums.begin()); + unique_nums.push_back(previous); + for(auto num : sorted_nums) { + if(previous != num) { + previous = num; + unique_nums.push_back(previous); + } + } + unique_nums.shrink_to_fit(); + return unique_nums; +} \ No newline at end of file From 27abbaa243c7dceeda2227e64bbf8ac8a78b20ca Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 14 Dec 2025 18:15:03 +0500 Subject: [PATCH 13/21] add solution: add task [range] --- 03_week/tasks/range/range.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/03_week/tasks/range/range.cpp b/03_week/tasks/range/range.cpp index d2085495..a9f67dc8 100644 --- a/03_week/tasks/range/range.cpp +++ b/03_week/tasks/range/range.cpp @@ -2,6 +2,29 @@ #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) { + int size = 0; + if(from == to || (from > to && step > 0) || (from < to && step < 0) || step == 0) { + return {}; + } + if ((step > 0 && from < to) || (step < 0 && from > to)) { + size = (std::abs(to - from) + std::abs(step) - 1) / std::abs(step); + } + std::vector sequence; + sequence.reserve(size); + + int current = from; + if (step > 0) { + while (current < to) { + sequence.push_back(current); + current += step; + } + } else { + while (current > to) { + sequence.push_back(current); + current += step; + } + } + + return sequence; } From a5f6e06b93587139cce0463320e1d03e24ec7812 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 14 Dec 2025 19:08:20 +0500 Subject: [PATCH 14/21] add solution: add task [minmax] --- 03_week/tasks/minmax/minmax.cpp | 43 +++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/03_week/tasks/minmax/minmax.cpp b/03_week/tasks/minmax/minmax.cpp index c2869799..68c8e928 100644 --- a/03_week/tasks/minmax/minmax.cpp +++ b/03_week/tasks/minmax/minmax.cpp @@ -1,6 +1,45 @@ #include +#include +using IntVecIterator = std::vector::const_iterator; -/* return_type */ MinMax(/* args */) { - throw std::runtime_error{"Not implemented"}; +std::pair MinMax(const std::vector& numbers) { + if (numbers.empty()) { + return {numbers.end(), numbers.end()}; + } + + IntVecIterator min_it = numbers.begin(); + IntVecIterator max_it = numbers.begin(); + + auto it = numbers.begin() + 1; + const auto last = numbers.end(); + + while (it + 1 < last) { + IntVecIterator a = it; + IntVecIterator b = it + 1; + + IntVecIterator local_min, local_max; + if (*a <= *b) { + local_min = a; + local_max = b; + } else { + local_min = b; + local_max = a; + } + + if (*local_min < *min_it) min_it = local_min; + if (*local_max >= *max_it) max_it = local_max; + + it += 2; + } + + if (it != last) { + if (*it < *min_it) { + min_it = it; + } else if (*it >= *max_it) { + max_it = it; + } + } + + return {min_it, max_it}; } From dca960ac502057f4cd84f5122410ae56d1222c2d Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 14 Dec 2025 19:50:16 +0500 Subject: [PATCH 15/21] add solution: add task [find_all] --- 03_week/tasks/find_all/find_all.cpp | 18 +++++++++++++++--- 1 file changed, 15 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..d2951d54 100644 --- a/03_week/tasks/find_all/find_all.cpp +++ b/03_week/tasks/find_all/find_all.cpp @@ -1,6 +1,18 @@ #include +#include - -/* return_type */ FindAll(/* args */) { - throw std::runtime_error{"Not implemented"}; +std::vector FindAll(const std::vector& container, bool (*predicate)(int)) { + if(container.empty() || predicate == nullptr) { + return {}; + } + + std::vector result; + + for (size_t i = 0; i < container.size(); ++i) { + if (predicate(container[i])) { + result.push_back(i); + } + } + result.shrink_to_fit(); + return result; } \ No newline at end of file From 81a216b9fa39b491ec3f83076c3742047b54bea0 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Mon, 15 Dec 2025 18:35:37 +0500 Subject: [PATCH 16/21] add solution: add task [os_overload] --- 03_week/tasks/os_overload/os_overload.cpp | 45 +++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/os_overload/os_overload.cpp b/03_week/tasks/os_overload/os_overload.cpp index e473418d..ba566298 100644 --- a/03_week/tasks/os_overload/os_overload.cpp +++ b/03_week/tasks/os_overload/os_overload.cpp @@ -1,21 +1,60 @@ #include #include #include +#include struct Coord2D { int x; int y; + Coord2D(int x_val = 0, int y_val = 0) : x(x_val), y(y_val) {} }; struct Circle { Coord2D coord; - unsigned radius; + unsigned radius = 1; + Circle() : coord(), radius(1) {} // Default + explicit Circle(Coord2D c, unsigned r = 1) : coord(c), radius(r) {} + Circle(unsigned r) : coord(), radius(r) {} }; using CircleRegion = std::pair; using CircleRegionList = std::vector; -/* return_type */ operator<<(/* args */) { - throw std::runtime_error{"Not implemented"}; +// Оператор вывода для Coord2D +std::ostream& operator<<(std::ostream& os, const Coord2D& coord) { + os << '(' << coord.x << ", " << coord.y << ')'; + return os; +} + +// Оператор вывода для Circle +std::ostream& operator<<(std::ostream& os, const Circle& circle) { + os << "circle["; + if (circle.radius > 0) { + os << circle.coord << ", r = " << circle.radius; + } + os << ']'; + return os; +} + +// Оператор вывода для CircleRegion +std::ostream& operator<<(std::ostream& os, const CircleRegion& region) { + os << (region.second ? '+' : '-') << region.first; + return os; +} + +std::ostream& operator<<(std::ostream& os, const CircleRegionList& circle_vector) { + os << '{'; + if (!circle_vector.empty()) { + os << '\n'; + for (auto it = circle_vector.begin(); it != circle_vector.end(); ++it) { + os << '\t' << *it; + if (std::next(it) != circle_vector.end()) { + os << ','; + } + os << '\n'; + } + } + os << '}'; + return os; } From 99c2021109e98bfef66da1081ea6d46dfffba696 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Tue, 16 Dec 2025 18:52:37 +0500 Subject: [PATCH 17/21] add solution: add task [easy_compare] --- 03_week/tasks/easy_compare/easy_compare.cpp | 48 ++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/03_week/tasks/easy_compare/easy_compare.cpp b/03_week/tasks/easy_compare/easy_compare.cpp index dd5cb7f6..b4509b2f 100644 --- a/03_week/tasks/easy_compare/easy_compare.cpp +++ b/03_week/tasks/easy_compare/easy_compare.cpp @@ -1,5 +1,12 @@ #include +#include +int markPriority(char mark) { + static const std::map priority = { + {'Z', 0}, {'D', 1}, {'C', 2}, {'B', 3}, {'A', 4} + }; + return priority.at(mark); +} struct Date { unsigned year; @@ -13,4 +20,43 @@ struct StudentInfo { int score; unsigned course; Date birth_date; -}; \ No newline at end of file +}; + +bool operator==(const Date& lhs, const Date& rhs) { + return std::tie(lhs.year, lhs.month, lhs.day) == + std::tie(rhs.year, rhs.month, rhs.day); +} + +bool operator<(const Date& lhs, const Date& rhs) { + return std::tie(lhs.year, lhs.month, lhs.day) < + std::tie(rhs.year, rhs.month, rhs.day); +} + +bool operator<=(const Date& lhs, const Date& rhs) { + return lhs < rhs || lhs == rhs; +} + +bool operator>(const Date& lhs, const Date& rhs) { + return !(lhs <= rhs); +} + +bool operator>=(const Date& lhs, const Date& rhs) { + return !(lhs < rhs); +} + +bool operator==(const StudentInfo& lhs, const StudentInfo& rhs) { + return lhs.mark == rhs.mark && lhs.score == rhs.score; +} + +bool operator<(const StudentInfo& lhs, const StudentInfo& rhs) { + if (markPriority(lhs.mark) != markPriority(rhs.mark)) { + return markPriority(lhs.mark) < markPriority(rhs.mark); + } + if (lhs.score != rhs.score) { + return lhs.score < rhs.score; + } + if (lhs.course != rhs.course) { + return lhs.course > rhs.course; + } + return lhs.birth_date < rhs.birth_date; +} From 0ecaae7b8fbd2d6dfe02123995af5f24ff3840c9 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Tue, 16 Dec 2025 19:04:29 +0500 Subject: [PATCH 18/21] add solution: add task [filter] --- 03_week/tasks/filter/filter.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/03_week/tasks/filter/filter.cpp b/03_week/tasks/filter/filter.cpp index 6648cb39..06fe0a15 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"}; +void Filter(std::vector& vec, bool (*predicate)(int)) { + size_t write_index = 0; + + if (vec.empty() || predicate == nullptr) { + return; + } + + for (size_t i = 0; i < vec.size(); ++i) { + if (predicate(vec[i])) { + if (i != write_index) { + vec[write_index] = vec[i]; + } + ++write_index; + } + } + vec.resize(write_index); } \ No newline at end of file From 5fda3fbb54bd977a93e279b75e818f5336539c3b Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Thu, 18 Dec 2025 17:00:25 +0500 Subject: [PATCH 19/21] =?UTF-8?q?=D0=94=D0=BB=D1=8F=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=B1=D0=B5=D0=B7=204=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04_week/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04_week/CMakeLists.txt b/04_week/CMakeLists.txt index 0531237e..91fe9074 100644 --- a/04_week/CMakeLists.txt +++ b/04_week/CMakeLists.txt @@ -7,7 +7,7 @@ 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) From bd5dc5a918a89eb99f8b586d518d60bab0bdce31 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Thu, 18 Dec 2025 17:10:42 +0500 Subject: [PATCH 20/21] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B0=20=D0=BF=D0=BE=20=D1=83=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E:=20Date:=20task=20we?= =?UTF-8?q?ek=5F03:=20easy=5Fcompare?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03_week/tasks/easy_compare/easy_compare.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/03_week/tasks/easy_compare/easy_compare.cpp b/03_week/tasks/easy_compare/easy_compare.cpp index b4509b2f..8145b476 100644 --- a/03_week/tasks/easy_compare/easy_compare.cpp +++ b/03_week/tasks/easy_compare/easy_compare.cpp @@ -9,9 +9,9 @@ int markPriority(char mark) { } struct Date { - unsigned year; - unsigned month; - unsigned day; + unsigned year = 0u; + unsigned month = 0u; + unsigned day = 0u; }; struct StudentInfo { From 77b1c249381b9991955ab31bbe2d306b3ca12433 Mon Sep 17 00:00:00 2001 From: Sergey Bobrovskikh Date: Sun, 21 Dec 2025 20:00:38 +0500 Subject: [PATCH 21/21] add solution add task [stack] --- 04_week/CMakeLists.txt | 2 +- 04_week/tasks/stack/stack.cpp | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/04_week/CMakeLists.txt b/04_week/CMakeLists.txt index e10ff9af..b15ca37c 100644 --- a/04_week/CMakeLists.txt +++ b/04_week/CMakeLists.txt @@ -7,7 +7,7 @@ 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) diff --git a/04_week/tasks/stack/stack.cpp b/04_week/tasks/stack/stack.cpp index 222e4ffc..7e1ee2fe 100644 --- a/04_week/tasks/stack/stack.cpp +++ b/04_week/tasks/stack/stack.cpp @@ -2,5 +2,63 @@ class Stack { + std::vector storage; +public: + Stack() = default; + ~Stack() = default; + void Push(int); + bool Pop(); + int& Top(); + const int& Top() const; + bool Empty() const; + size_t Size() const; + void Clear(); + void Swap(Stack&); + friend bool operator==(const Stack& lhs, const Stack& rhs); + friend bool operator!=(const Stack&, const Stack&); }; + +void Stack::Push(int a) { + storage.push_back(a); +} + +bool Stack::Pop() { + if(storage.empty()) { + return false; + } + storage.pop_back(); + return true; +} + +int& Stack::Top() { + return storage.back(); +} + +const int& Stack::Top() const { + return storage.back(); +} + +bool Stack::Empty() const { + return storage.empty(); +} + +size_t Stack::Size() const { + return storage.size(); +} + +void Stack::Clear() { + storage.clear(); +} + +void Stack::Swap(Stack& other) { + storage.swap(other.storage); +} + +bool operator==(const Stack& lhs, const Stack& rhs) { + return lhs.storage == rhs.storage; +} + +bool operator!=(const Stack& lhs, const Stack& rhs) { + return lhs.storage != rhs.storage; +}