Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
83ca1d7
add (solution): add char_changer task
TookTM Nov 25, 2025
a133a8d
add (solution): add char_changer task
TookTM Nov 25, 2025
f593781
Merge branch 'psds-cpp:main' into main
TookTM Nov 26, 2025
8c8b1df
add (solution): add addition2 task
TookTM Nov 26, 2025
ae14a5a
add (solution): add check_flags task
TookTM Nov 26, 2025
4c4bbdf
add (solution): add length_lit task
TookTM Nov 26, 2025
5815706
add (solution): add print_bits task
TookTM Nov 26, 2025
6201fcf
add (solution): add rms task
TookTM Nov 26, 2025
4620677
add rms2 task
TookTM Nov 26, 2025
b73b9b8
add quadratic task
TookTM Nov 26, 2025
34a9a4e
Merge branch 'psds-cpp:main' into main
TookTM Dec 2, 2025
9930417
add (solution): add func_array task
TookTM Dec 3, 2025
53e1f09
add (solution): add func_array1 task
TookTM Dec 3, 2025
1877c2b
Merge branch 'psds-cpp:main' into main
TookTM Dec 5, 2025
df4918e
add (solution): add swap_ptr task
TookTM Dec 5, 2025
72c0db7
add (solution): add longest task
TookTM Dec 5, 2025
0ea827e
add (solution): add pretty_array task
TookTM Dec 8, 2025
fdb1b70
add (solution): add last_of_us task
TookTM Dec 9, 2025
f04d35e
add (solution): add little_big task
TookTM Dec 9, 2025
2caaf16
Merge branch 'psds-cpp:main' into main
TookTM Dec 16, 2025
728bdb1
add (solution): add proverka task
TookTM Dec 17, 2025
6693bc7
add (solution): add data_stats task
TookTM Dec 17, 2025
a91e20f
add (solution): add easy_compare task
TookTM Dec 17, 2025
e4133b8
add (solution): add enum_operators task
TookTM Dec 18, 2025
0adb815
add (solution): add comment cmake task
TookTM Dec 18, 2025
891f816
add (solution): add comment_cmake task
TookTM Dec 18, 2025
df82b9c
add (solution): add filter task
TookTM Dec 18, 2025
1c9157c
add (solution): add find_all task
TookTM Dec 18, 2025
66f8597
add (solution): add minmax task
TookTM Dec 18, 2025
33c8359
add (solution): add os_overload task
TookTM Dec 18, 2025
f591253
add (solution): add range task
TookTM Dec 18, 2025
be5fe75
add (solution): add range_1 task
TookTM Dec 18, 2025
413666d
add (solution): add unique task
TookTM Dec 18, 2025
1b507a1
Merge branch 'psds-cpp:main' into main
TookTM Dec 23, 2025
6dda849
add (solution): add cmake task
TookTM Dec 23, 2025
baaa204
add (solution): add phasor task
TookTM Dec 24, 2025
0529a82
add (solution): add stack task
TookTM Dec 24, 2025
73054a8
add (solution): add queue task
TookTM Dec 25, 2025
6b185e6
add (solution): add ring_buffer task
TookTM 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
2 changes: 1 addition & 1 deletion 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
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.

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

}
52 changes: 51 additions & 1 deletion 01_week/tasks/char_changer/char_changer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,55 @@


size_t CharChanger(char array[], size_t size, char delimiter = ' ') {
throw std::runtime_error{"Not implemented"};
if (size == 0) return 0;

char* pread = array;
char* pwrite = array;

while (*pread != '\0' && (pread - array) < static_cast<ptrdiff_t>(size - 1)) {
char tek_char = *pread;
int repeat_count = 1;

// Ограничиваем подсчет повторений границами массива
while (repeat_count < static_cast<int>(size - (pread - array)) &&
pread[repeat_count] == tek_char) {
repeat_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.

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

}

if (tek_char == ' ') {
*pwrite = delimiter;
pwrite++;
pread += repeat_count;
continue;
}

char temp;
if (std::isdigit(tek_char)) {
temp = '*';
} else if (std::isupper(tek_char)) {
temp = tek_char;
} else if (std::islower(tek_char)) {
temp = std::toupper(tek_char);
} else {
temp = '_';
}

*pwrite = temp;
pwrite++;

if (repeat_count > 1) {
if (repeat_count >= 10) {
*pwrite = '0';
pwrite++;
} else {
*pwrite = '0' + repeat_count;
pwrite++;
}
}

pread += repeat_count;
}

*pwrite = '\0';
return pwrite - array;
}
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,6 +1,6 @@
#include <cstdint>
#include <stdexcept>

#include <iostream>

enum class CheckFlags : uint8_t {
NONE = 0,
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);

// Проверяем, что значение находится в допустимом диапазоне
if (value > static_cast<uint8_t>(CheckFlags::ALL)) {
return; // значение вне диапазона - ничего не выводим
}

if (value == 0) {
std::cout << "[]"; // нет флагов - выводим []
return;
}

std::cout << "[";

if (value & 1) std::cout << "TIME";
if (value & 2) std::cout << (value & 1 ? ",DATE" : "DATE");
Copy link
Contributor Author

@18thday 18thday Jan 19, 2026

Choose a reason for hiding this comment

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

  • можно тогда по тернарному оператору "," : "", а уже потом добавлять "DATE"
  • также можно ',' вынести в переменную, так как в случае необходимости добавления пробела,", ", нужно бы было менять в одном месте

if (value & 4) std::cout << (value & 3 ? ",USER" : "USER");
if (value & 8) std::cout << (value & 7 ? ",CERT" : "CERT");
if (value & 16) std::cout << (value & 15 ? ",KEYS" : "KEYS");
if (value & 32) std::cout << (value & 31 ? ",DEST" : "DEST");
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 << "]";
}
47 changes: 47 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
constexpr double operator""_ft_to_m(long double feet) {
return feet * 0.3048;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

magic values не принято использовать в коде, корректнее было определить константы 0.3048 0.0254 0.01 например и выполнять преобразования с их использованием, можно даже разместить их в безымянном namespace, чтобы область видимости была только в данной единице трансляции

}

constexpr double operator""_in_to_m(long double inches) {
return inches * 0.0254;
}

constexpr double operator""_cm_to_m(long double centimeters) {
return centimeters * 0.01;
}

constexpr double operator""_m_to_ft(long double meters) {
return meters / 0.3048;
}

constexpr double operator""_m_to_in(long double meters) {
return meters / 0.0254;
}

constexpr double operator""_m_to_cm(long double meters) {
return meters / 0.01;
}

constexpr double operator""_ft_to_cm(long double feet) {
return operator""_m_to_cm(operator""_ft_to_m(feet));
}

constexpr double operator""_ft_to_in(long double feet) {
return operator""_m_to_in(operator""_ft_to_m(feet));
}

constexpr double operator""_in_to_ft(long double inches) {
return operator""_m_to_ft(operator""_in_to_m(inches));
}

constexpr double operator""_in_to_cm(long double inches) {
return operator""_m_to_cm(operator""_in_to_m(inches));
}

constexpr double operator""_cm_to_ft(long double centimeters) {
return operator""_m_to_ft(operator""_cm_to_m(centimeters));
}

constexpr double operator""_cm_to_in(long double centimeters) {
return operator""_m_to_in(operator""_cm_to_m(centimeters));
}
29 changes: 26 additions & 3 deletions 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
#include <cstddef>
#include <stdexcept>

#include <cstddef>
#include <iostream>

void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
if (bytes < 1 || bytes > 8) {
return;
}

std::cout << "0b";

size_t total_bits = bytes * 8;
size_t bits_printed = 0;

// Проходим по всем битам от старшего к младшему
for (int byte = bytes - 1; byte >= 0; --byte) {
for (int bit = 7; bit >= 0; --bit) {
// Получаем текущий бит (сдвигаем и маскируем)
long long current_bit = (value >> (byte * 8 + bit)) & 1;
std::cout << current_bit;
bits_printed++;
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 (bits_printed % 4 == 0 && bits_printed < total_bits) {
std::cout << "'";
}
}
}

std::cout << std::endl;
}
58 changes: 56 additions & 2 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stdexcept>


void SolveQuadratic(int a, int b, int c) {
throw std::runtime_error{"Not implemented"};
// a,b,c=0
if (a == 0 && b == 0 && c == 0) {
std::cout << "infinite solutions";
return;
}

// a=0
if (a == 0) {
if (b == 0) {
// c=0
if (c == 0) {
std::cout << "infinite 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.

лучше преобразовать в короткие ветви по условиям, с выходом из функции, так намного удобнее читать, чем вложенность, каждый особый случай обрабатывать отдельно, будет немного больше сравнений с 0, но они достаточно дешевые, а читаемость значительно повысится:
как сделано в начале)

if (a == 0 && b == 0 && c == 0) {
    std::cout << "infinite solutions";
    return;
}

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

if (a == 0 && b == 0) {
    std::cout << (c == 0 ? "infinite solutions" : "no solutions");
    return;
}
if (a == 0) {
     // b*x+c=0
     ...
}

} else {
std::cout << "no solutions";
}
} else {
// b*x+c=0
double x = -static_cast<double>(c) / b;
// Обработка случая -0.0
if (std::abs(x) < 1e-10) x = 0.0;
std::cout << std::setprecision(6) << x;
}
return;
}

// Вычисление D
double discriminant = static_cast<double>(b) * b - 4.0 * a * c;

if (discriminant < 0) {
// D<0
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.

лучше в коротких ветвях ставить return, а дальше убирать else из условий, это лучше тем, что не нужно листать дальше код, чтобы узнать, что больше к выводу ничего не добавляется

} else if (discriminant == 0) {
// D=0
double x = -static_cast<double>(b) / (2.0 * a);
// Обработка случая -0.0
if (std::abs(x) < 1e-10) x = 0.0;
std::cout << std::setprecision(6) << x;
} else {
// D>0
double sqrt_d = std::sqrt(discriminant);
double x1 = (-b - sqrt_d) / (2.0 * a);
double x2 = (-b + sqrt_d) / (2.0 * a);

// Обработка случая -0.0 для обоих корней
if (std::abs(x1) < 1e-10) x1 = 0.0;
if (std::abs(x2) < 1e-10) x2 = 0.0;

if (x1 > x2) {
std::swap(x1, x2);
}

std::cout << std::setprecision(6) << x1 << " " << x2;
}
}
20 changes: 17 additions & 3 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#include <cstdef>
#include <stdexcept>

#include <cmath>
#include <cstddef>

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

// Вычисление суммы квадратов элементов
double sum1 = 0.0;
for (size_t i = 0; i < size; ++i) {
sum1 += values[i] * values[i];
}

// Вычисление среднеквадратического значения
double squares = sum1 / size;
Copy link
Contributor Author

@18thday 18thday Jan 19, 2026

Choose a reason for hiding this comment

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

имена переменных странные всё-таки sum - это уже сумма квадратов, а здесь мы просто делим на количество. зачем нужна 1 в имени также не понятно

double rms = std::sqrt(squares);

return rms;
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

}
15 changes: 13 additions & 2 deletions 02_week/tasks/func_array/func_array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include <stdexcept>


double ApplyOperations(double a, double b /* other arguments */) {
throw std::runtime_error{"Not implemented"};
double ApplyOperations(double a, double b, double (**ops)(double, double), size_t size) {
if (ops == nullptr || size == 0) {
Copy link
Contributor Author

@18thday 18thday Jan 19, 2026

Choose a reason for hiding this comment

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

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

return 0.0;
}

double sum = 0.0;
for (size_t i = 0; i < size; ++i) {
if (ops[i] != nullptr) {
sum += ops[i](a, b);
}
}

return sum;
}
15 changes: 13 additions & 2 deletions 02_week/tasks/last_of_us/last_of_us.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#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 || end == nullptr || begin == nullptr) {
return end;
}
const int* p_pred = end;

for (size_t i = 1; (end-i) != (begin-1); ++i) {
if (predicate(*(end-i))) {
p_pred = end-i;
return p_pred;
}
}
return p_pred;
}
48 changes: 42 additions & 6 deletions 02_week/tasks/little_big/little_big.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <cstring>


void PrintMemory(int /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(int value, bool invert = false) {
//memcpy копирует байты из числа в массив
unsigned char bytes[sizeof(int)];
std::memcpy(bytes, &value, sizeof(int));

std::cout << "0x" << std::uppercase << std::hex;

if (!invert) {
for (size_t i = 0; i < sizeof(int); ++i) {
unsigned int byte_value = bytes[i];
std::cout << std::setw(2) << std::setfill('0') << byte_value;
}
} else {
for (int i = sizeof(int) - 1; i >= 0; --i) {
unsigned int byte_value = bytes[i];
std::cout << std::setw(2) << std::setfill('0') << byte_value;
}
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::endl;
}

void PrintMemory(double /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(double value, bool invert = false) {
unsigned char bytes[sizeof(double)];
std::memcpy(bytes, &value, sizeof(double));

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 и тогда избавится от дублирования вызывая эту функцию как из версии для int и double

std::cout << "0x" << std::uppercase << std::hex;

if (!invert) {
for (size_t i = 0; i < sizeof(double); ++i) {
unsigned int byte_value = bytes[i];
std::cout << std::setw(2) << std::setfill('0') << byte_value;
}
} else {
for (int i = sizeof(double) - 1; i >= 0; --i) {
unsigned int byte_value = bytes[i];
std::cout << std::setw(2) << std::setfill('0') << byte_value;
}
}

std::cout << std::endl;
}
Loading