-
Notifications
You must be signed in to change notification settings - Fork 33
Плотников Денис #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Плотников Денис #20
Changes from all commits
5ba6a4e
585a9f1
1d52181
9972097
bdba583
a72a5f8
b33b075
5fa34f5
c6d8dde
b15a6ea
483d3ff
a96ef72
a564807
7896d5f
357f0d7
3bad216
6073431
9355f90
2f504ca
536cb4f
1d32809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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); | ||
| } | ||
| 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 {}; // индекс записи | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. пробел обычо не ставят перед |
||
|
|
||
| while (array[src] != '\0' && src < size) { | ||
| char c { array[src++] }; // текущий символ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] }; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. как будто лучше вместо else опставить условие |
||
| // без изменений | ||
| } 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); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в данном случае просится тернарный оператор в одну строку |
||
| } | ||
| } | ||
|
|
||
| return (array[dst] = '\0', dst); // позиция конца строки | ||
| } | ||
| 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 { | ||
|
|
@@ -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) }; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. на каждом цикле считать There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если В таком случае и статичность |
||
| 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; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это круто, понравилось решение, единственное нет отступа у case |
||
| first = false; | ||
| } | ||
| } | ||
| out += ']'; | ||
| std::cout << out; | ||
| } | ||
| 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); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше в коде избегать magic value (за исключением 100 наверное), неплохо бы завести безымянный namespace с понятными константами 2.54, 0.3048, 12 и их использовать |
||
| 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); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) }; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно использовать литерал для |
||
| const bool bs { (value & mask) != 0 }; | ||
| out += (bs ? '1' : '0'); | ||
| if ((i + 1) % 4 == 0 && i + 1 < bits) { | ||
| out += '\''; | ||
| } | ||
| } | ||
| std::cout << out << std::endl; | ||
|
|
||
| } | ||
| 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"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. может проверок меньше но вложенность не так выразительна, как разбить на отдельные случаи |
||
| } else { | ||
| std::cout << "no solutions"; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| 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)); | ||
| } |
| 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)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не совсем понятно зачем нужна обертка, если функция принимает по значению |
||
| } | ||
|
|
||
| return sum; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лишний каст, второй операнд кастовать не обязателен, так как произойдет неявный каст к
int64_t, и принято этим пользоваться, оставляя код чище