Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
aa06b1f
Update addition.cpp
karskanovas Nov 28, 2025
240b2e7
Addition task (#1)
karskanovas Nov 28, 2025
8374322
ignore build directory
karskanovas Nov 28, 2025
73267df
add: add length_lit task
karskanovas Nov 28, 2025
4b96e10
add: add print_bits task
karskanovas Nov 28, 2025
71bc667
add: add quadratic task
karskanovas Nov 28, 2025
b570327
add: add rms task
karskanovas Nov 28, 2025
7be7e34
fix: add addition task
karskanovas Nov 28, 2025
15175f3
fix: add char_changer task
karskanovas Nov 28, 2025
392bcb2
fix: add check_flags task
karskanovas Nov 28, 2025
8c32ee1
fix: add length_lit task
karskanovas Nov 28, 2025
620df85
fix: add print_bits task
karskanovas Nov 28, 2025
49b333b
fix: add quadratic task
karskanovas Nov 28, 2025
2171651
fix: add rms task
karskanovas Nov 28, 2025
46982b6
fix: add addition task
karskanovas Nov 28, 2025
c8ec7eb
Auto-sync: 2025-12-01 19:19
actions-user Dec 1, 2025
a7f167e
Auto-sync: 2025-12-02 09:46
actions-user Dec 2, 2025
2e8f4d9
Auto-sync: 2025-12-03 07:00
actions-user Dec 3, 2025
a67e355
Auto-sync: 2025-12-03 12:28
actions-user Dec 3, 2025
bd129ad
func_array
karskanovas Dec 9, 2025
0c30f21
last of us
karskanovas Dec 9, 2025
edfd91a
little big
karskanovas Dec 9, 2025
7450931
longer
karskanovas Dec 9, 2025
319b6f3
pretty_array
karskanovas Dec 9, 2025
5e9f0cf
swap_ptr
karskanovas Dec 9, 2025
ed641e9
Merge upstream/main
karskanovas Dec 18, 2025
43dcac3
data_stats
karskanovas Dec 19, 2025
465b6f1
Fix CMakeLists.txt for 04_week temporarily
karskanovas Dec 19, 2025
3e84f50
easy_compar
karskanovas Dec 19, 2025
e805cf1
enum_operators.cpp
karskanovas Dec 19, 2025
109d2c5
filter
karskanovas Dec 19, 2025
8a5d6b8
find_all.cpp
karskanovas Dec 19, 2025
2f9c89a
minmax
karskanovas Dec 19, 2025
b9c1606
os_overload
karskanovas Dec 19, 2025
f952ce2
range
karskanovas Dec 19, 2025
6e2d037
range
karskanovas Dec 19, 2025
090484b
update range
karskanovas Dec 19, 2025
7132675
unique
karskanovas Dec 19, 2025
08992b7
Merge upstream/main, keep local changes
karskanovas Dec 26, 2025
1056207
phasor
karskanovas Dec 26, 2025
3a3eb3f
Delete CMakeLists.txt.save
karskanovas Dec 26, 2025
befa598
Update CMakeLists.txt
karskanovas Dec 26, 2025
6607112
queue
karskanovas Dec 26, 2025
fc2bec1
ring_buffer
karskanovas Dec 26, 2025
e32646e
stack
karskanovas Dec 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:

tasks=("addition" "rms" "print_bits" "check_flags" "length_lit" "quadratic" "char_changer"
"swap_ptr" "func_array" "longest" "last_of_us" "little_big" "pretty_array"
"data_stats" "unique" "range" "minmax" "find_all" "os_overload" "easy_compare" "filter" "enum_operators"
"stack" "queue" "ring_buffer" "phasor")
"data_stats" "unique" "range" "minmax" "find_all" "os_overload" "easy_compare" "filter" "enum_operators")

declare -i passed_count=0
declare -i failed_count=0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing_week_03.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
- enum_operators

schedule:
- cron: '59 20 19 12 *' # UTC: 20:59 = 23:59 MSK 19 December
- cron: '59 20 18 12 *' # UTC: 20:59 = 23:59 MSK 18 December

jobs:
test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
6 changes: 3 additions & 3 deletions 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <cstdint>
#include <stdexcept>


int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
}

Copy link
Contributor Author

@18thday 18thday Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лишняя строка

return static_cast<int64_t>(a) + static_cast<int64_t>(b);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишний каст, второй операнд не следует приводить явно, так как он бы преобразовался с помощью неявно. Принято использовать такую возможность и не писать явный каст самостоятельно второй раз

}
46 changes: 42 additions & 4 deletions 01_week/tasks/char_changer/char_changer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
#include <cstddef>
#include <stdexcept>

#include <cctype>
#include <cstring>

size_t CharChanger(char array[], size_t size, char delimiter = ' ') {
throw std::runtime_error{"Not implemented"};
}
size_t w = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше расположить рядом с r, а ещё лучше все таки назвать w_pos r_pos или wr_pos rd_pos, кажется так понятнее назначение

auto map_char = [&](char ch) -> char {
unsigned char uc = ch; //в этом месте возникала ошибка, решено использовать unsigner
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему бы тогда не принимать сразу unsigned char ch?

if (std::isspace(uc)) return delimiter;
if (std::isdigit(uc)) return '*';
if (std::isalpha(uc)) return (char)std::toupper(uc);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Принято не использовать C-style каст, а использовать C++ касты, в данном случае static_cast

return '_'; };
size_t r = 0;
while (r < size && array[r] != '\0') {
char current = array[r];
char mapped = map_char(current);
size_t count = 1;
size_t next = r + 1;
while (next < size && array[next] != '\0') {
char next_char = array[next];
char mapped_next = map_char(next_char);
if (mapped_next != mapped) break;
if (mapped == '*' || mapped == '_') {
if (current != next_char) break;
} else if (mapped >= 'A' && mapped <= 'Z') {
unsigned char curr_uc = current;
unsigned char next_uc = next_char;
if (std::islower(curr_uc) != std::islower(next_uc)) break; }
count++;
next++;}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • инкременты должны быть префиксные
  • } общепринято на новой строке, чтобы визуально while выделялся блоком кода, аналогично для if for else switch и других конструкций

unsigned char current_uc = current;
bool is_space_seq = (mapped == delimiter) && std::isspace(current_uc);
if (is_space_seq) {
bool is_letter_delimiter = (delimiter >= 'A' && delimiter <= 'Z');
if (is_letter_delimiter || w == 0 || array[w - 1] != delimiter) {
array[w++] = delimiter;}
} else {
array[w++] = mapped;
if (count > 1) {
char repeat_char = (count < 10) ? ('0' + count) : '0';
array[w++] = repeat_char;}}
r += count; }
array[w] = '\0';
return w;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно было переработать алгоритм и сделать его лаконичнее и логичнее, есть проверки, которых можно было избежать, переписав программу

}
25 changes: 23 additions & 2 deletions 01_week/tasks/check_flags/check_flags.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <cstdint>
#include <stdexcept>
#include <iostream>


enum class CheckFlags : uint8_t {
Expand All @@ -14,5 +14,26 @@ enum class CheckFlags : uint8_t {
};

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
uint8_t value = static_cast<uint8_t>(flags);
uint8_t all = static_cast<uint8_t>(CheckFlags::ALL);
if ((value & ~all) != 0) {
return; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Закрывающая скобка на новой строке

if (value == 0) {
std::cout << "[]";
return;}
std::cout << "[";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

эта строка должна быть перед вызовами print_flag, так будет удобнее читать код

bool first = true;
auto print_flag = [&](CheckFlags f, const char* name) {
if (value & static_cast<uint8_t>(f)) {
if (!first) std::cout << ",";
std::cout << name;
first = false;}
};
print_flag(CheckFlags::TIME, "TIME");
print_flag(CheckFlags::DATE, "DATE");
print_flag(CheckFlags::USER, "USER");
print_flag(CheckFlags::CERT, "CERT");
print_flag(CheckFlags::KEYS, "KEYS");
print_flag(CheckFlags::DEST, "DEST");
std::cout << "]";
}
50 changes: 50 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <cstdint>


constexpr long double operator"" _ft_to_m(long double v) {
return static_cast<double>(v * 0.3048L);
}

constexpr long double operator"" _ft_to_in(long double v) {
return static_cast<double>(v * 12.0L);
}

constexpr long double operator"" _ft_to_cm(long double v) {
return static_cast<double>(v * 30.48L);
}

constexpr long double operator"" _in_to_ft(long double v) {
return static_cast<double>(v / 12.0L);
}

constexpr long double operator"" _in_to_m(long double v) {
return static_cast<double>(v * 0.0254L);
}

constexpr long double operator"" _in_to_cm(long double v) {
return static_cast<double>(v * 2.54L);
}

constexpr long double operator"" _cm_to_in(long double v) {
return static_cast<double>(v / 2.54L);
}

constexpr long double operator"" _cm_to_ft(long double v) {
return static_cast<double>(v / 30.48L);
}

constexpr long double operator"" _cm_to_m(long double v) {
return static_cast<double>(v / 100.0L);
}

constexpr long double operator"" _m_to_cm(long double v) {
return static_cast<double>(v * 100.0L);
}

constexpr long double operator"" _m_to_in(long double v) {
return static_cast<double>(v / 0.0254L);
}

constexpr long double operator"" _m_to_ft(long double v) {
return static_cast<double>(v / 0.3048L);
}
Copy link
Contributor Author

@18thday 18thday Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не принято использовать magic value в коде (кроме 100, 1000 и т.п.), правильнее добавить константы, например, 12, 2.54, 30.48, видимые в данном файле с помощью безымянного namespace

16 changes: 13 additions & 3 deletions 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include <cstddef>
#include <stdexcept>
#include <iostream>


void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
}
if (bytes == 0 || bytes > 8)
return;
std::cout << "0b";
size_t total_bits = bytes * 8;
for (size_t i = 0; i < total_bits; ++i) {
size_t bit_index = total_bits - 1 - i;
bool bit = (value >> bit_index) & 1;
std::cout << (bit ? '1' : '0');
if (i % 4 == 3 && i + 1 < total_bits)
std::cout << "'"; }
std::cout << "\n";
}
37 changes: 35 additions & 2 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
#include <stdexcept>
#include <iostream>
#include <cmath>


void SolveQuadratic(int a, int b, int c) {
throw std::runtime_error{"Not implemented"};
auto print = [](double x) {
if (std::abs(x) < 1e-9) x = 0;
if (std::abs(x - std::round(x)) < 1e-9) {
std::cout << static_cast<long long>(std::round(x));
} else {
x = std::round(x * 1e6) / 1e6; //округление (тест)
std::cout << x;}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в данном случае при выводе в поток, всё долджно было быть корректно и манипуляции дополнительные излишни

if (a == 0) {
if (b == 0) {
if (c == 0) std::cout << "infinite solutions";
else std::cout << "no solutions";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

так компактнее конечно, но появляется несколько уровней вложенности, что не очень хорошо. Обычно принято отдельные особые случаи выделять короткими ветвями, в данной задаче лучше было бы разделить на отдельные условия для infinite solutions, no solutions и одного корня

} else {
double x = -static_cast<double>(c) / b;
print(x);}
return;}
double D = static_cast<double>(b) * b - 4.0 * a * c;
if (D < 0) {
std::cout << "no solutions";
} else if (D == 0) {
double x = -static_cast<double>(b) / (2.0 * a);
print(x);
} else {
double sqrtD = std::sqrt(D);
double x1 = (-b - sqrtD) / (2.0 * a);
double x2 = (-b + sqrtD) / (2.0 * a);
if (x1 > x2) {
double temp = x1;
x1 = x2;
x2 = temp;}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нагляднее и правильнее использовать готовую функцию std::swap

print(x1);
std::cout << " ";
print(x2);}
}
12 changes: 9 additions & 3 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#include <cstdef>
#include <cstddef>
#include <cmath>
#include <stdexcept>


double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
}
if (size == 0) return 0.0;
if (values == nullptr) return 0.0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

часто если по условиям возвращаются одинаковые значения лучше их объединить логическим ИЛИ

double sum_squares = 0.0;
for (size_t i = 0; i < size; ++i) {
sum_squares += values[i] * values[i];}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

закрывающая скобка на новой строке

return std::sqrt(sum_squares / static_cast<double>(size));
}
16 changes: 11 additions & 5 deletions 02_week/tasks/func_array/func_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <stdexcept>
#include <cstddef>


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) {
if (size == 0 || operations == nullptr) {
return 0.0;}
double sum = 0.0;
for (size_t i = 0; i < size; ++i) {
if (operations[i] != nullptr) {
sum += operations[i](a, b);
} }
return sum;
}
14 changes: 10 additions & 4 deletions 02_week/tasks/last_of_us/last_of_us.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <stdexcept>


/* 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 || !end || begin > end) {
return end;}
const int* result = end;
for (const int* ptr = begin; ptr < end; ++ptr) {
if (predicate(*ptr)) {
result = ptr;}
}
return result;
}
34 changes: 29 additions & 5 deletions 02_week/tasks/little_big/little_big.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
#include <iostream>
#include <iomanip>
#include <stdexcept>

void PrintMemory(int value, bool reverse = false) {// Для int
unsigned char* bytes = reinterpret_cast<unsigned char*>(&value);
std::cout << "0x" << std::uppercase;
if (reverse) {
for (size_t i = sizeof(int); i > 0; --i) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(bytes[i - 1]); }
} else {
for (size_t i = 0; i < sizeof(int); ++i) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(bytes[i]); }
}
std::cout << std::dec << std::endl;
}

void PrintMemory(int /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(double value, bool reverse = false) {// Для double
unsigned char* bytes = reinterpret_cast<unsigned char*>(&value);
std::cout << "0x" << std::uppercase;
if (reverse) {
for (size_t i = sizeof(double); i > 0; --i) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(bytes[i - 1]); }
} else {
for (size_t i = 0; i < sizeof(double); ++i) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(bytes[i]); }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в данном случае тоже дублирование, можно было использовать тернарный оператор в нужных местах, либо вынести настройку std::cout

}
std::cout << std::dec << std::endl;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В данном случае практически полное дублирование кода. После приведения к указателю на символ и зная sizeof от типа, правильнее было вызвать третью функцию которая уже печатает требуемое представление


void PrintMemory(double /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
}
30 changes: 28 additions & 2 deletions 02_week/tasks/longest/longest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#include <cstddef>
#include <stdexcept>

char* FindLongestSubsequence(char* begin, char* end, size_t& count) {
if (!begin || !end || begin >= end) {
count = 0;
return nullptr; }
char* max_start = begin;
size_t max_len = 1;
char* current_start = begin;
size_t current_len = 1;
for (char* ptr = begin + 1; ptr < end; ++ptr) {
if (*ptr == *(ptr - 1)) {
++current_len;}
else {
if (current_len > max_len) {
max_len = current_len;
max_start = current_start;
}
current_start = ptr;
current_len = 1;}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот так корректно и так должно быть везде

if (current_len > max_len) {
max_len = current_len;
max_start = current_start;}
count = max_len;
return max_start;
}

/* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) {
throw std::runtime_error{"Not implemented"};
const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) { //из за ошибки про то, что ожидается изменяемый массив
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

немного некорректное описание проблемы

return FindLongestSubsequence(const_cast<char*>(begin), const_cast<char*>(end), count);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это некорректно, это UB, должно быть наоборот, снимать const можно, если изначально был объект не конст, то есть из версии без константности, можно вызвать константную (где весь код из текущей неконстантной версии), а затем снять константность, но никак не наоборот, в данном случае это UB

}
Loading
Loading