-
Notifications
You must be signed in to change notification settings - Fork 33
Жамбакиев Радий #34
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?
Жамбакиев Радий #34
Changes from all commits
7154dec
abb00b8
4141f23
16fe4e3
e6233b8
520f1f2
057cea0
5af2950
f2b2c19
bff7344
7345a15
706b609
6d51ad2
6a45716
3febd06
cc12364
1aaa0c9
635fcdf
e26d95b
aabca70
12fe9b9
45ed16c
44d8762
8504d0e
6b566ab
d455bf1
7a87f24
5afec6c
0c21b29
7bc19a1
2adfae0
f128b9c
42b81c6
23e327e
e81fc9c
6095c22
9efba7f
83f3bce
55ccf15
5b5b649
a9ddb14
bd18c29
857c48f
0ebcff7
0a479eb
270198a
8f37dc1
d05dff0
1da7fd8
666f3ee
0a672bb
0f8501b
fedc8a6
cc40f74
983130f
d224fa1
2bf0972
4bbad35
5202c54
5f36202
3f3d8e0
a6e8ad5
a5b7743
23296e3
826f2d3
b12e33f
9e16a6c
915d830
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,2 @@ | ||
| /build | ||
| /build-asan |
| 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) + b; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,71 @@ | ||
| #include <cctype> | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
|
|
||
| // Есть ощущение, что это можно решить как-то более лаконично и просто | ||
|
|
||
| /** | ||
| * @brief Получить длину последовательности из одинаковых знаков. | ||
| * @param array указатель на элемент массива, с которого начнется проверка. | ||
| * @return Длина последовательности. | ||
| * @note Все символы будут сравниваться с первым из переданного массива. | ||
| */ | ||
| size_t GetIdenticalCharSequenceLen(char *array) { | ||
| size_t sequenceLen = 0; | ||
| if (array[0] == '\0') return 0; | ||
| while (array[0] == array[sequenceLen]) ++sequenceLen; | ||
| return sequenceLen; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Сконвертировать одинаковые символы. | ||
| * @param array указатель на начало обрабатываемого массива. | ||
| * @param convertedSymIdx ссылка на индекс последнего сконвертированного символа. | ||
| * @param currentSymIdx ссылка на индекс текущего обрабатываемого символа. | ||
| * @param swapChar символ, на который будет произведена замена array[convertedSymIdx]. | ||
| * @return none | ||
| */ | ||
| void ConvertIdenticalCharacters(char array[], size_t& convertedSymIdx, size_t& currentSymIdx, char swapChar) { | ||
| size_t sequenceLen = GetIdenticalCharSequenceLen(&array[currentSymIdx]); | ||
|
|
||
| array[convertedSymIdx++] = swapChar; | ||
|
|
||
| if (sequenceLen == 1) { | ||
| currentSymIdx += sequenceLen; | ||
| return; | ||
| } | ||
|
|
||
| array[convertedSymIdx++] = sequenceLen >= 10 ? '0' : sequenceLen + '0'; | ||
|
|
||
| currentSymIdx += sequenceLen; | ||
| } | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| size_t convertedSymbolIdx = 0, currentSymbolIdx = 0; | ||
|
|
||
| while(currentSymbolIdx < size && convertedSymbolIdx < size) { | ||
| if (array[currentSymbolIdx] == '\0') { | ||
| break; | ||
| } | ||
|
|
||
| if (isspace(array[currentSymbolIdx])) { | ||
| currentSymbolIdx += GetIdenticalCharSequenceLen(&array[currentSymbolIdx]); | ||
| array[convertedSymbolIdx++] = delimiter; | ||
| continue; | ||
| } | ||
|
|
||
| if (isalnum(array[currentSymbolIdx])) { | ||
| if (isdigit(array[currentSymbolIdx])) { | ||
| ConvertIdenticalCharacters(array, convertedSymbolIdx, currentSymbolIdx, '*'); | ||
| continue; | ||
| } | ||
|
|
||
| ConvertIdenticalCharacters(array, convertedSymbolIdx, currentSymbolIdx, toupper(array[currentSymbolIdx])); | ||
| continue; | ||
| } | ||
|
|
||
| ConvertIdenticalCharacters(array, convertedSymbolIdx, currentSymbolIdx, '_'); | ||
| } | ||
|
|
||
| array[convertedSymbolIdx] = '\0'; | ||
| return convertedSymbolIdx; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #include <cstdint> | ||
| #include <stdexcept> | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| enum class CheckFlags : uint8_t { | ||
| NONE = 0, | ||
|
|
@@ -13,6 +14,43 @@ enum class CheckFlags : uint8_t { | |
| ALL = TIME | DATE | USER | CERT | KEYS | DEST | ||
| }; | ||
|
|
||
| namespace { | ||
| const std::vector<std::pair<CheckFlags, std::string_view>> checkNames = { | ||
| {CheckFlags::TIME, "TIME"}, | ||
| {CheckFlags::DATE, "DATE"}, | ||
| {CheckFlags::USER, "USER"}, | ||
| {CheckFlags::CERT, "CERT"}, | ||
| {CheckFlags::KEYS, "KEYS"}, | ||
| {CheckFlags::DEST, "DEST"}, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| void PrintCheckFlags(CheckFlags flags) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if (flags > CheckFlags::ALL) { | ||
| return; | ||
| } | ||
|
|
||
| if (flags == CheckFlags::NONE) { | ||
| std::cout << "[]"; | ||
| return; | ||
| } | ||
|
|
||
| std::string needed_checks = "["; | ||
|
|
||
| bool first = true; | ||
| for (const auto& [key, val] : checkNames) { | ||
| if (static_cast<uint8_t>(flags) & static_cast<uint8_t>(key)) { | ||
| if (!first) { | ||
| needed_checks += ","; | ||
| } | ||
|
|
||
| needed_checks += val; | ||
| first = false; | ||
| } | ||
| } | ||
|
|
||
| needed_checks += "]"; | ||
|
|
||
| std::cout << needed_checks; | ||
|
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. с тем же успехом можно было сразу писать в поток (буфур потока), линейная логика |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| constexpr long double METER_IN_FOOT = 0.3048; | ||
| constexpr long double INCH_IN_FOOT = 12; | ||
| constexpr long double METER_IN_INCH = 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. это хорошо |
||
|
|
||
| constexpr long double operator""_ft_to_m(long double foot) { | ||
| return foot * METER_IN_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_m_to_ft(long double meter) { | ||
| return meter / METER_IN_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_ft_to_cm(long double foot) { | ||
| return foot * METER_IN_FOOT * 100; | ||
| } | ||
|
|
||
| constexpr long double operator""_cm_to_ft(long double cm) { | ||
| return cm / (METER_IN_FOOT * 100); | ||
| } | ||
|
|
||
| constexpr long double operator""_ft_to_in(long double foot) { | ||
| return foot * INCH_IN_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_in_to_ft(long double inch) { | ||
| return inch / INCH_IN_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_in_to_m(long double inch) { | ||
| return inch * METER_IN_INCH; | ||
| } | ||
|
|
||
| constexpr long double operator""_m_to_in(long double meter) { | ||
| return meter / METER_IN_INCH; | ||
| } | ||
|
|
||
| constexpr long double operator""_in_to_cm(long double inch) { | ||
| return inch * METER_IN_INCH * 100; | ||
| } | ||
|
|
||
| constexpr long double operator""_cm_to_in(long double inch) { | ||
| return inch / (METER_IN_INCH * 100); | ||
| } | ||
|
|
||
| constexpr long double operator""_m_to_cm(long double meter) { | ||
| return meter * 100; | ||
| } | ||
|
|
||
| constexpr long double operator""_cm_to_m(long double cm) { | ||
| return cm / 100; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
|
|
||
| #include <string> | ||
|
|
||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| std::string byteForm = "0b"; | ||
| // i < bytes * 8 сработает, потому что 0ULL - 1 переполняется в ULL_MAX | ||
| for (size_t i = (bytes * 8 - 1); i < bytes * 8; --i) { | ||
| byteForm += ((value >> i) & 0x01U) + '0'; | ||
|
|
||
| if (i != 0 && i % 4 == 0) { | ||
| byteForm += "'"; | ||
| } | ||
| } | ||
|
|
||
| std::cout << byteForm << std::endl; | ||
|
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. можно сразу писать в буфер потока, но так тоже хорошо |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,61 @@ | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
|
|
||
| // Уверен, что это можно сделать значительно качественнее, но дедлайн близко, | ||
| // поэтому спагетти код >:) | ||
|
|
||
| void SolveQuadratic(int a, int b, int c) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| void SolveQuadratic(int a, int b, int c) { | ||
| if (a == 0 && b == 0 && c == 0) { | ||
| std::cout << "infinite solutions"; | ||
| return; | ||
| } | ||
|
|
||
| if (a == 0 && b == 0) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
|
|
||
| std::cout << std::setprecision(6); | ||
|
|
||
| if (a == 0) { | ||
| std::cout << static_cast<double>(-c) / b; | ||
| return; | ||
| } | ||
|
|
||
| if (b == 0) { | ||
| if (static_cast<double>(-c) / a < 0) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
|
|
||
| double root = std::sqrt(static_cast<double>(-c) / a); | ||
|
|
||
| if (root == 0) { | ||
| std::cout << root; | ||
| } else { | ||
| std::cout << -root << " " << root; | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| double discriminant = static_cast<double>(b) * b - 4.0 * a * c; | ||
| double root1 = 0.0, root2 = 0.0; | ||
|
|
||
| if (discriminant == 0) { | ||
| std::cout << -b / (2.0 * a); | ||
| return; | ||
| } | ||
|
|
||
| if (discriminant < 0) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
|
|
||
| root1 = ((-b - std::sqrt(discriminant)) / (2.0 * a)); | ||
| root2 = ((-b + std::sqrt(discriminant)) / (2.0 * a)); | ||
|
|
||
| root1 > root2 ? std::cout << root2 << " " << root1 : | ||
| std:: cout << root1 << " " << root2; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| #include <cstdef> | ||
| #include <stdexcept> | ||
|
|
||
| #include <cstddef> | ||
| #include <cmath> | ||
|
|
||
| double CalculateRMS(double values[], size_t size) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| if (size == 0 || !values) { | ||
| return 0.0; | ||
| } | ||
|
|
||
| double sum = 0.0; | ||
| for (size_t i = 0; i < size; ++i) { | ||
| sum += values[i] * values[i]; | ||
| } | ||
|
|
||
| return std::sqrt(sum / static_cast<double>(size)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,18 @@ | ||
| #include <stdexcept> | ||
| #include <cstddef> | ||
|
|
||
| using operations_t = double(*)(double, double); | ||
|
|
||
| double ApplyOperations(double a, double b /* other arguments */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| double ApplyOperations(double a, double b, operations_t mathOperations[], size_t size) { | ||
| if (size == 0 || mathOperations == nullptr) { | ||
| return 0.0; | ||
| } | ||
|
|
||
| double sum = 0.0; | ||
| for (size_t i = 0; i < size; ++i) { | ||
| if (mathOperations[i] != nullptr) { | ||
| sum += mathOperations[i](a, b); | ||
| } | ||
| } | ||
|
|
||
| return sum; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,17 @@ | ||
| #include <stdexcept> | ||
| typedef bool (*predicate_func_t)(int); | ||
|
|
||
| const int* FindLastElement(const int* begin, const int* end, predicate_func_t predicate) { | ||
| if (!begin || !end || begin >= end) { | ||
| return end; | ||
| } | ||
|
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 int* result = end; | ||
| while (begin != end) { | ||
| if (predicate(*begin)) { | ||
| result = begin; | ||
| } | ||
| ++begin; | ||
| } | ||
|
|
||
| /* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| return result; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,29 @@ | ||
| #include <stdexcept> | ||
| #include <cstring> | ||
| #include <iostream> | ||
|
|
||
| template<typename T> | ||
| void PrintMemory(T num, bool isReversed = false) { | ||
| std::string output = ""; | ||
|
|
||
| void PrintMemory(int /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| // Надеюсь использование memcpy разрешено | ||
|
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. тут больше ожидалось reinterpret_cast, чтобы поупражняться |
||
| unsigned char bytes[sizeof(T)]; | ||
| std::memcpy(bytes, &num, sizeof(T)); | ||
|
|
||
| size_t start = isReversed ? (sizeof(T) - 1) : 0; | ||
| int step = isReversed ? -1 : 1; | ||
|
|
||
| for (size_t i = start; i < sizeof(T); i += step) { | ||
| unsigned char currentByte = bytes[i]; | ||
|
|
||
| for (int j = 4; j >= 0; j -= 4) { | ||
| int remainder = (currentByte >> j) & 0xf; | ||
| char hexChar = 0; | ||
|
|
||
| void PrintMemory(double /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| hexChar = remainder < 10 ? '0' + remainder : 'A' + (remainder - 10); | ||
|
|
||
| output += hexChar; | ||
| } | ||
| } | ||
| output = "0x" + output; | ||
| std::cout << output << std::endl; | ||
| } | ||
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.
много лишних пустых строк