Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5ba6a4e
Update .gitignore
Di0nisP Nov 25, 2025
585a9f1
feat(01_week): add working implementation
Di0nisP Nov 25, 2025
1d52181
Merge branch 'psds-cpp:main' into main
Di0nisP Nov 25, 2025
9972097
fix (01_week): name `bitset` -> `bs`
Di0nisP Nov 26, 2025
bdba583
perf (01_week): using constexpr
Di0nisP Nov 26, 2025
a72a5f8
Merge branch 'psds-cpp:main' into main
Di0nisP Dec 4, 2025
b33b075
feat (02_weak): add working implementation
Di0nisP Dec 7, 2025
5fa34f5
Merge branch 'psds-cpp:main' into main
Di0nisP Dec 15, 2025
c6d8dde
Merge pull request #1 from Di0nisP/dev
Di0nisP Dec 15, 2025
b15a6ea
Merge remote-tracking branch 'upstream/main'
Di0nisP Dec 15, 2025
483d3ff
feat (03_week): add working implementation
Di0nisP Dec 17, 2025
a96ef72
fix (04_week): comment out add_subdirectory for tasks in CMakeLists
Di0nisP Dec 17, 2025
a564807
Update CMakeLists.txt
18thday Dec 18, 2025
7896d5f
Merge branch 'main' into dev
Di0nisP Dec 21, 2025
357f0d7
Merge pull request #2 from Di0nisP/dev
Di0nisP Dec 21, 2025
3bad216
Revert "Update CMakeLists.txt"
Di0nisP Dec 21, 2025
6073431
Merge branch 'psds-cpp:main' into main
Di0nisP Dec 21, 2025
9355f90
Merge branch 'psds-cpp:main' into main
Di0nisP Dec 23, 2025
2f504ca
feat (04_weak): add working implementation
Di0nisP Dec 24, 2025
536cb4f
fix (04_weak): Pop() in ring_buffer
Di0nisP Dec 24, 2025
1d32809
Merge pull request #3 from Di0nisP/dev
Di0nisP Jan 1, 2026
7484c31
Merge branch 'psds-cpp:main' into main
Di0nisP Feb 9, 2026
565d3bd
feat (05_week): add working implementation
Di0nisP Feb 12, 2026
6a82ccd
Merge pull request #4 from Di0nisP/dev
Di0nisP Feb 12, 2026
89ddb6f
fix (05_week): rule of 5
Di0nisP Feb 12, 2026
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
83 changes: 83 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# .gitignore для psds-cpp-2025 (C++ проект)

# Каталоги сборки и артефакты
/build/
/cmake-build-*/
/out/
/bin/
/obj/
/dist/

# CMake, Make и тесты
CMakeFiles/
CMakeCache.txt
cmake_install.cmake
CTestTestfile.cmake
Makefile

# Скомпилированные файлы и библиотеки
*.o
*.obj
*.so
*.a
*.lib
*.dll
*.exe
*.out
*.elf
*.app

# Отладочные файлы и логи
*.pdb
*.ilk
*.log

# Профилирование / покрытие
*.gcda
*.gcno
coverage.*
lcov-report/

# Автогенерированные файлы инструментов
compile_commands.json
conanbuildinfo.*
.conan/

# IDE / редакторы
.vscode/
.idea/
*.iml
*.ipr
*.iws
*.sublime-*
*.code-workspace

# Системные файлы
.DS_Store
Thumbs.db

# Временные файлы редакторов
*~
*.swp
*.swo
*.tmp
.#*

# Архивы и артефакты релизов
*.tar.gz
*.zip

# Документация
docs/_build/
doc/html/

# Прочее
.tags
.ccls-cache/
*.lock

# Индексные файлы (.idx)
*.idx
*.IDX
*.idx~
*.idx.bak
4 changes: 1 addition & 3 deletions 01_week/tasks/addition/addition.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <cstdint>
#include <stdexcept>


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

@18thday 18thday Dec 24, 2025

Choose a reason for hiding this comment

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

Лишний каст, второй операнд кастовать не обязателен, так как произойдет неявный каст к int64_t, и принято этим пользоваться, оставляя код чище

}
49 changes: 48 additions & 1 deletion 01_week/tasks/char_changer/char_changer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
#include <cctype>
#include <cstddef>
#include <stdexcept>


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

size_t src {}; // индекс чтения
size_t dst {}; // индекс записи
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 (array[src] != '\0' && src < size) {
char c { array[src++] }; // текущий символ
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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


// Подсчет количества одинаковых символов
size_t count {1};
while (array[src] != '\0' && src < size) {
const char next { array[src] };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лучше не именовать переменную используемую в единственном месте, а использовать по месту, тем более на следующем цикле она уже не next, а next_next

if (c != next)
break;
count++;
src++;
}

// Изменение символа в соответствии с правилами
bool isspace {};
if (std::isdigit(static_cast<unsigned char>(c))) {
c = '*';
} else if (std::islower(static_cast<unsigned char>(c))) {
c = std::toupper(static_cast<unsigned char>(c));
} else if (std::isupper(static_cast<unsigned char>(c))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

как будто лучше вместо else опставить условие !std::isupper(), а данную проверку убрать

// без изменений
} else if (std::isspace(static_cast<unsigned char>(c))) {
c = delimiter;
isspace = true;
} else {
c = '_';
}

// Запись измененного символа и количества в массив
array[dst++] = c;
if (count > 1 && !isspace) {
if (count >= 10) {
array[dst++] = '0';
} else {
array[dst++] = static_cast<char>('0' + 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 (array[dst] = '\0', dst); // позиция конца строки
}
39 changes: 36 additions & 3 deletions 01_week/tasks/check_flags/check_flags.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <bit>
#include <cstdint>
#include <stdexcept>
#include <iostream>
#include <utility>


enum class CheckFlags : uint8_t {
Expand All @@ -13,6 +15,37 @@ enum class CheckFlags : uint8_t {
ALL = TIME | DATE | USER | CERT | KEYS | DEST
};

void PrintCheckFlags(CheckFlags flags) {
throw std::runtime_error{"Not implemented"};
void PrintCheckFlags(CheckFlags flags) {
constexpr static const auto all { static_cast<uint8_t>(CheckFlags::ALL) };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Считаю это излишним, так как применяется в единственном месте, и переменная мало весит, чтобы её делать static, не уверен что будет эффекктивнее чем ходить недалеко по стеку, вероятно лучше по месту применить каст

const auto value { static_cast<uint8_t>(flags) };

// Есть биты вне диапазона
if ((value & ~all) != 0) {
std::cout << "";
return;
}

if (value == static_cast<uint8_t>(CheckFlags::NONE)) {
std::cout << "[]";
return;
}

std::string out {'['};
bool first { true };
for (uint8_t i = 0; std::cmp_less(i, std::popcount(all)); ++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::popcount(all) не целесообразно

Copy link

Choose a reason for hiding this comment

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

Если all помечено constexpr и std::popcount --- тоже constexpr, то разве будет выполняться пересчёт на каждой итерации?

В таком случае и статичность all кажется вполне уместной.

if ((value & (1u << i)) != 0) {
if (!first) out += ',';
switch (i) {
case 0: out += "TIME"; break;
case 1: out += "DATE"; break;
case 2: out += "USER"; break;
case 3: out += "CERT"; break;
case 4: out += "KEYS"; break;
case 5: out += "DEST"; break;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Это круто, понравилось решение, единственное нет отступа у case

first = false;
}
}
out += ']';
std::cout << out;
}
59 changes: 59 additions & 0 deletions 01_week/tasks/length_lit/length_lit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Футы → метры
constexpr double operator""_ft_to_m(long double v) {
return static_cast<double>(v * 0.3048);
}

// Футы → сантиметры
constexpr double operator""_ft_to_cm(long double v) {
return static_cast<double>(v * 30.48);
}

// Футы → дюймы
constexpr double operator""_ft_to_in(long double v) {
return static_cast<double>(v * 12.0);
}

// Дюймы → футы
constexpr double operator""_in_to_ft(long double v) {
return static_cast<double>(v / 12.0);
}

// Дюймы → сантиметры
constexpr double operator""_in_to_cm(long double v) {
return static_cast<double>(v * 2.54);
}

// Дюймы → метры
constexpr double operator""_in_to_m(long double v) {
return static_cast<double>(v * 0.0254);
}

// Сантиметры → метры
constexpr double operator""_cm_to_m(long double v) {
return static_cast<double>(v / 100.0);
}

// Сантиметры → дюймы
constexpr double operator""_cm_to_in(long double v) {
return static_cast<double>(v / 2.54);
}

// Сантиметры → футы
constexpr double operator""_cm_to_ft(long double v) {
return static_cast<double>(v / 30.48);
}

// Метры → сантиметры
constexpr double operator""_m_to_cm(long double v) {
return static_cast<double>(v * 100.0);
}

// Метры → футы
constexpr double operator""_m_to_ft(long double v) {
return static_cast<double>(v / 0.3048);
}

// Метры → дюймы
constexpr double operator""_m_to_in(long double v) {
return static_cast<double>(v / 0.0254);
}
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 value (за исключением 100 наверное), неплохо бы завести безымянный namespace с понятными константами 2.54, 0.3048, 12 и их использовать

22 changes: 20 additions & 2 deletions 01_week/tasks/print_bits/print_bits.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
#include <cstddef>
#include <stdexcept>

#include <iostream>

void PrintBits(long long value, size_t bytes) {
throw std::runtime_error{"Not implemented"};
using value_t = decltype(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.

для использования в одном месте немного сомнительно


if (bytes == 0 || bytes > sizeof(value)) {
throw std::invalid_argument("Invalid number of bytes");
}

const auto bits { bytes * 8 };

std::string out { "0b" };
for (size_t i = 0; i < bits; ++i) {
const value_t mask { (static_cast<value_t>(1) << (bits - 1 - 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.

можно использовать литерал для long long будет более выразительно нагромождения с псевдонимом

const bool bs { (value & mask) != 0 };
out += (bs ? '1' : '0');
if ((i + 1) % 4 == 0 && i + 1 < bits) {
out += '\'';
}
}
std::cout << out << std::endl;

}
41 changes: 39 additions & 2 deletions 01_week/tasks/quadratic/quadratic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <cmath>


void SolveQuadratic(int a, int b, int c) {
throw std::runtime_error{"Not implemented"};
constexpr const int precision { 6 };

// Сохраняем текущее состояние потока
std::ios oldState(nullptr);
oldState.copyfmt(std::cout);

std::cout << std::setprecision(precision);

if (a == 0) {
if (b == 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.

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

} 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.

в данно случае можно и тернарный вместо 5 строк использовать

} else {
std::cout << -static_cast<double>(c) / b;
}
} else {
const int d { b * b - 4 * a * c };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

D тогда уж, но по-хорошему нужно не пожалеть символов и написатьдискриминант

if (d < 0) {
std::cout << "no solutions";
} else if (d == 0) {
if (b == 0) {
std::cout << "0";
} else {
std::cout << -static_cast<double>(b) / (2 * a);
}
} else {
const double sqrt_d { std::sqrt(d) };
std::cout << (-b - sqrt_d) / (2 * a) << ' ' << (-b + sqrt_d) / (2 * a);
}
}

// Восстанавливаем состояние потока
std::cout.copyfmt(oldState);
}
20 changes: 18 additions & 2 deletions 01_week/tasks/rms/rms.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
#include <cstdef>
#include <cstddef>
#include <stdexcept>
#include <span>
#include <cmath>


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

std::span<double> dataSpan(values, size);

double rms {};
for (const auto& value : dataSpan) {
if (!std::isfinite(value)) {
throw std::invalid_argument("Array contains non-finite values");
}
rms += value * value;
}

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


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 operations_count) {
if (operations_count == 0) {
return 0.0;
}

double sum {};

for (size_t i = 0; i < operations_count; ++i) {
if (operations[i] == nullptr) continue;
sum += operations[i](std::as_const(a), std::as_const(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.

не совсем понятно зачем нужна обертка, если функция принимает по значению

}

return sum;
}
Loading