From 19015b8c9bd3cf9a5199a3a00c937ac47529b9b0 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:45:12 +0500 Subject: [PATCH 01/12] add (solution): add addition 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..78f77b24 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 x1 = a; + int64_t x2 = b; + return x1 + x2; } \ No newline at end of file From c07a84f9cb475d7f3196a1aa59fe091c1f83a524 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:47:33 +0500 Subject: [PATCH 02/12] add (solution): add char_changer task --- 01_week/tasks/char_changer/char_changer.cpp | 69 ++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/01_week/tasks/char_changer/char_changer.cpp b/01_week/tasks/char_changer/char_changer.cpp index 3a7344d9..4c0963d8 100644 --- a/01_week/tasks/char_changer/char_changer.cpp +++ b/01_week/tasks/char_changer/char_changer.cpp @@ -1,7 +1,72 @@ #include #include - +#include size_t CharChanger(char array[], size_t size, char delimiter = ' ') { - throw std::runtime_error{"Not implemented"}; + if (size == 0) return 0; + + size_t pos_read = 0; // позиция чтения + size_t pos_write = 0; // позиция записи + + while (array[pos_read] != '\0') { // проверка на последний символ + char current_char = array[pos_read]; // изменяемый символ + size_t count = 1; + + while (pos_read + count < size && array[pos_read + count] == current_char) { // подсчет повторающихся символов + ++count; + } + + if (isdigit(current_char)) {// проверка на цифры + current_char = '*'; + } + else if (islower(current_char)) { // проверка на строчные буквы + current_char = toupper(current_char); + } + else if (!isupper(current_char) && current_char != ' ') { //остальные символы, кроме пробелов и прописных букв + current_char = '_'; + } + + if (current_char == ' ') { // оработка пробелов + current_char = delimiter; + if (pos_write < size) { + array[pos_write] = current_char; + ++pos_write; + } + } + + else { // обработка остальных символов + if (pos_write < size) { //записываем символ + array[pos_write] = current_char; + ++pos_write; + } + if ( count > 1) { ///обрабатываем повторения + if (count >= 10) { + if (pos_write < size) { + array[pos_write] = '0'; + ++pos_write; + } + } + else { + if (pos_write < size) { + array[pos_write] = '0' + count; + ++pos_write; + } + } + } + } + pos_read += count; + } + + + + // Добавляем завершающий нуль-символ + if (pos_write < size) { + array[pos_write] = '\0'; + } + else if (size > 0) { + array[size - 1] = '\0'; + pos_write = size - 1; + } + + return pos_write; } From 5a48cacc47f5632fd6bfecaffd49c59244b2c0c7 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:48:33 +0500 Subject: [PATCH 03/12] add (solution): add check_flags task --- 01_week/tasks/check_flags/check_flags.cpp | 42 ++++++++++++++++++++++- 1 file changed, 41 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..6545624a 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,44 @@ enum class CheckFlags : uint8_t { }; void PrintCheckFlags(CheckFlags flags) { - throw std::runtime_error{"Not implemented"}; + uint8_t value = static_cast(flags); + + if (value > static_cast(CheckFlags::ALL)) { + return; + } + + // Обработка специального случая NONE + if (flags == CheckFlags::NONE) { + std::cout << "[]"; + return; + } + + std::cout<< "["; + const char* comma = ""; + if ((value & static_cast(CheckFlags::TIME)) !=0) { + std::cout<< comma << "TIME"; + comma = ","; + } + if ((value & static_cast(CheckFlags::DATE)) !=0) { + std::cout<< comma << "DATE"; + comma = ","; + } + if ((value & static_cast(CheckFlags::USER)) !=0) { + std::cout<< comma << "USER"; + comma = ","; + } + if ((value & static_cast(CheckFlags::CERT)) !=0) { + std::cout<< comma << "CERT"; + comma = ","; + } + if ((value & static_cast(CheckFlags::KEYS)) !=0) { + std::cout<< comma << "KEYS"; + comma = ","; + } + if ((value & static_cast(CheckFlags::DEST)) !=0) { + std::cout<< comma << "DEST"; + comma = ","; + } + + std::cout<<"]"; } From 6d62fdffdd2237306f77bdf915028fc99d09bd16 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:49:20 +0500 Subject: [PATCH 04/12] add (solution): add length_lit task --- 01_week/tasks/length_lit/length_lit.cpp | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/01_week/tasks/length_lit/length_lit.cpp b/01_week/tasks/length_lit/length_lit.cpp index e69de29b..861c90a8 100644 --- a/01_week/tasks/length_lit/length_lit.cpp +++ b/01_week/tasks/length_lit/length_lit.cpp @@ -0,0 +1,44 @@ + +namespace length_const { + constexpr double METER = 1.0; + constexpr double CENTIMETER = 0.01; + constexpr double FOOT = 0.3048; + constexpr double INCH = 0.0254; +} + +constexpr double operator""_ft_to_in(long double value) { + return value * length_const::FOOT / length_const::INCH; +} +constexpr double operator""_ft_to_cm(long double value) { + return value * length_const::FOOT / length_const::CENTIMETER; +} +constexpr double operator""_ft_to_m(long double value) { + return value * length_const::FOOT / length_const::METER; +} +constexpr double operator""_in_to_ft(long double value) { + return value * length_const::INCH / length_const::FOOT; +} +constexpr double operator""_in_to_cm(long double value) { + return value * length_const::INCH / length_const::CENTIMETER; +} +constexpr double operator""_in_to_m(long double value) { + return value * length_const::INCH / length_const::METER; +} +constexpr double operator""_cm_to_ft(long double value) { + return value * length_const::CENTIMETER / length_const::FOOT; +} +constexpr double operator""_cm_to_in(long double value) { + return value * length_const::CENTIMETER / length_const::INCH; +} +constexpr double operator""_cm_to_m(long double value) { + return value * length_const::CENTIMETER / length_const::METER; +} +constexpr double operator""_m_to_ft(long double value) { + return value * length_const::METER / length_const::FOOT; +} +constexpr double operator""_m_to_in(long double value) { + return value * length_const::METER / length_const::INCH; +} +constexpr double operator""_m_to_cm(long double value) { + return value * length_const::METER / length_const:: CENTIMETER; +} From 4f6aa1731c1130c6cc0d325fe010a95190455e54 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:50:26 +0500 Subject: [PATCH 05/12] add (solution): add print_bits task --- 01_week/tasks/print_bits/print_bits.cpp | 16 +++++++++++++++- 1 file changed, 15 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..938a362d 100644 --- a/01_week/tasks/print_bits/print_bits.cpp +++ b/01_week/tasks/print_bits/print_bits.cpp @@ -1,7 +1,21 @@ #include #include +#include void PrintBits(long long value, size_t bytes) { - throw std::runtime_error{"Not implemented"}; + if (bytes == 0 || bytes > 8) { + return; + } + + std::cout << "0b"; + for (int i = static_cast(bytes * 8 - 1); i >= 0; i--) { + unsigned long long bit = (static_cast(value) >> i) & 1; + std::cout << bit; + + if (i > 0 && i % 4 == 0) { + std::cout << "'"; + } + } + std::cout << std::endl; } From 9305fef723e6f573c7384a06a1f4836e49108833 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:51:05 +0500 Subject: [PATCH 06/12] add (solution): add quadratic task --- 01_week/tasks/quadratic/quadratic.cpp | 50 +++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/01_week/tasks/quadratic/quadratic.cpp b/01_week/tasks/quadratic/quadratic.cpp index abf7d632..8c02b919 100644 --- a/01_week/tasks/quadratic/quadratic.cpp +++ b/01_week/tasks/quadratic/quadratic.cpp @@ -1,6 +1,50 @@ +#include +#include +#include #include - void SolveQuadratic(int a, int b, int c) { - throw std::runtime_error{"Not implemented"}; -} \ No newline at end of file + std::cout << std::defaultfloat << std::setprecision(6); + + if (a == 0 && b == 0 && c == 0) { + std::cout << "infinite solutions"; + return; + } + + if (a == 0) { + if (b == 0) { + std::cout << "no solutions"; + } + else { + double x = -static_cast(c) / b; + if (x == -0) { + x = 0; + } + std::cout << x; + } + return; + } + + double discriminant = static_cast(b) * b - 4.0 * a * c; + if (discriminant < 0) { + std::cout << "no solutions"; + } + else if (discriminant == 0) { + double x = -static_cast(b) / (2.0 * a); + if (x == -0) { + x = 0; + } + std::cout << x; + } + else { + double sqrt_d = std::sqrt(discriminant); + double x1 = (-static_cast(b) - sqrt_d) / (2.0 * a); + double x2 = (-static_cast(b) + sqrt_d) / (2.0 * a); + + if (x1 > x2) { + std::swap(x1, x2); + } + + std::cout << x1 << " " << x2; + } +} From 0b2043ca150d61867b97a1d0f16378a35862f4c9 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Fri, 28 Nov 2025 19:51:30 +0500 Subject: [PATCH 07/12] add (solution): add rms task --- 01_week/tasks/rms/rms.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/01_week/tasks/rms/rms.cpp b/01_week/tasks/rms/rms.cpp index 6882f0a9..d88b7ec5 100644 --- a/01_week/tasks/rms/rms.cpp +++ b/01_week/tasks/rms/rms.cpp @@ -1,7 +1,18 @@ -#include #include - +#include double CalculateRMS(double values[], size_t size) { - throw std::runtime_error{"Not implemented"}; -} \ No newline at end of file + if (size == 0 || values == nullptr) { + return 0.0; + } + + double sum_of_squares = 0.0; + for (size_t i = 0; i < size; ++i) { + sum_of_squares += values[i] * values[i]; + } + + double mean_of_squares = sum_of_squares / size; + double rms = std::sqrt(mean_of_squares); + + return rms; +} From 982008fc7ca8dc9be0007c902bc65fdb8db271ac Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Mon, 8 Dec 2025 20:10:32 +0500 Subject: [PATCH 08/12] add (solution): add func_array task --- 02_week/tasks/func_array/func_array.cpp | 15 +++++++++++++-- 1 file changed, 13 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..b74ae517 100644 --- a/02_week/tasks/func_array/func_array.cpp +++ b/02_week/tasks/func_array/func_array.cpp @@ -1,6 +1,17 @@ #include -double ApplyOperations(double a, double b /* other arguments */) { - throw std::runtime_error{"Not implemented"}; +double ApplyOperations(double a, double b, double (*operations[])(double, double), size_t size ) { + double sum = 0.0; + + if (operations == nullptr || size == 0) { + return 0.0; + } + + for (size_t i = 0; i < size; ++i) { + if (operations[i] != nullptr) { + sum += operations[i](a, b); + } + } + return sum; } \ No newline at end of file From 50cb31e0ee36ccda3f247f03edae21571021c9f1 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Mon, 8 Dec 2025 21:06:19 +0500 Subject: [PATCH 09/12] add (solution): add last_of_us task --- 02_week/tasks/last_of_us/last_of_us.cpp | 12 ++++++++++-- 1 file changed, 10 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..8ab15bad 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,14 @@ #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)(int)) { + if (begin == nullptr || begin == nullptr || begin > end || begin == end) { + 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 598856c11f09997479a84601f9f6c31e0e4bb7d2 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Wed, 17 Dec 2025 20:30:05 +0500 Subject: [PATCH 10/12] add (solution): add little_big task --- 02_week/tasks/little_big/little_big.cpp | 45 +++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/02_week/tasks/little_big/little_big.cpp b/02_week/tasks/little_big/little_big.cpp index abe24379..37acf5d1 100644 --- a/02_week/tasks/little_big/little_big.cpp +++ b/02_week/tasks/little_big/little_big.cpp @@ -1,10 +1,43 @@ #include +#include +#include +#include +#include - -void PrintMemory(int /* write arguments here */) { - throw std::runtime_error{"Not implemented"}; +void PrintMemory(int value, bool reverse = false) { + uint32_t bytes; + std::memcpy(&bytes, &value, sizeof(value)); + + if (reverse) { + // Оригинальный порядок байт (big-endian представление) + std::cout << "0x" << std::uppercase << std::hex << std::setfill('0') << std::setw(8) + << bytes << "\n"; + } else { + // Little-endian представление (байты в обратном порядке) + uint32_t reversed = 0; + for (size_t i = 0; i < sizeof(value); ++i) { + reversed = (reversed << 8) | ((bytes >> (i * 8)) & 0xFF); + } + std::cout << "0x" << std::uppercase << std::hex << std::setfill('0') << std::setw(8) + << reversed << "\n"; + } } -void PrintMemory(double /* write arguments here */) { - throw std::runtime_error{"Not implemented"}; -} \ No newline at end of file +void PrintMemory(double value, bool reverse = false) { + uint64_t bytes; + std::memcpy(&bytes, &value, sizeof(value)); + + if (reverse) { + // Оригинальный порядок байт (big-endian представление) + std::cout << "0x" << std::uppercase << std::hex << std::setfill('0') << std::setw(16) + << bytes << "\n"; + } else { + // Little-endian представление (байты в обратном порядке) + uint64_t reversed = 0; + for (size_t i = 0; i < sizeof(value); ++i) { + reversed = (reversed << 8) | ((bytes >> (i * 8)) & 0xFF); + } + std::cout << "0x" << std::uppercase << std::hex << std::setfill('0') << std::setw(16) + << reversed << "\n"; + } +} From 145ca6cd52c7882bf91d1a95d74aa139d32cbf10 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Wed, 17 Dec 2025 20:32:31 +0500 Subject: [PATCH 11/12] add (solution): add little_big task --- 02_week/tasks/little_big/little_big.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/02_week/tasks/little_big/little_big.cpp b/02_week/tasks/little_big/little_big.cpp index 37acf5d1..5150eb97 100644 --- a/02_week/tasks/little_big/little_big.cpp +++ b/02_week/tasks/little_big/little_big.cpp @@ -9,11 +9,9 @@ void PrintMemory(int value, bool reverse = false) { std::memcpy(&bytes, &value, sizeof(value)); if (reverse) { - // Оригинальный порядок байт (big-endian представление) std::cout << "0x" << std::uppercase << std::hex << std::setfill('0') << std::setw(8) << bytes << "\n"; } else { - // Little-endian представление (байты в обратном порядке) uint32_t reversed = 0; for (size_t i = 0; i < sizeof(value); ++i) { reversed = (reversed << 8) | ((bytes >> (i * 8)) & 0xFF); @@ -28,11 +26,9 @@ void PrintMemory(double value, bool reverse = false) { std::memcpy(&bytes, &value, sizeof(value)); if (reverse) { - // Оригинальный порядок байт (big-endian представление) std::cout << "0x" << std::uppercase << std::hex << std::setfill('0') << std::setw(16) << bytes << "\n"; } else { - // Little-endian представление (байты в обратном порядке) uint64_t reversed = 0; for (size_t i = 0; i < sizeof(value); ++i) { reversed = (reversed << 8) | ((bytes >> (i * 8)) & 0xFF); From bbfb636354bffb22cf17eb45324ade70e4ba10d2 Mon Sep 17 00:00:00 2001 From: Nikonov Sergey Date: Wed, 17 Dec 2025 20:34:59 +0500 Subject: [PATCH 12/12] add (solution): add longest task --- 02_week/tasks/longest/longest.cpp | 40 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/02_week/tasks/longest/longest.cpp b/02_week/tasks/longest/longest.cpp index 04b3c354..a7c6e9f7 100644 --- a/02_week/tasks/longest/longest.cpp +++ b/02_week/tasks/longest/longest.cpp @@ -1,6 +1,40 @@ #include - -/* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) { - throw std::runtime_error{"Not implemented"}; +char* FindLongestSubsequence(char* begin, char* end, size_t& count) { + if (begin == nullptr || end == nullptr || begin > end ||begin == end) { + count = 0; + return nullptr; + } + + char* current_start = begin; // Начало текущей последовательности + char* longest_start = begin; // Начало самой длинной последовательности + size_t current_length = 1; // Длина текущей последовательности + size_t max_length = 1; // Максимальная длина найденной последовательности + + // Проходим по всем элементам, начиная со второго + for (char* it = begin + 1; it != end; ++it) { + if (*it == *(it - 1)) { + current_length++; + } else { + if (current_length > max_length) { + max_length = current_length; + longest_start = current_start; + } + current_start = it; + current_length = 1; + } + } + + if (current_length > max_length) { + max_length = current_length; + longest_start = current_start; + } + + count = max_length; + return longest_start; } + +const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) { + char* result = FindLongestSubsequence(const_cast(begin), const_cast(end), count); + return result; +} \ No newline at end of file