-
Notifications
You must be signed in to change notification settings - Fork 33
Гатин Ленар #24
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?
Гатин Ленар #24
Changes from all commits
7e5f6fd
918f221
674d723
3e0971d
8888db2
6ba1cc7
03782e6
6d671ea
c36c0b9
2b0311d
a1eb37d
2901a4a
70b6212
fcce802
3b1e4ba
f316b43
c187692
bef6f6f
7942e20
4e843ca
b5e6048
8bec754
99f7f9f
d56fc84
6c80a35
495147e
3aca2a2
fd63ae4
da78a7e
1769325
c8693f4
18eedf4
5321d62
bf4e7b8
70ff77d
fca57cf
171b60e
a178ff3
77b1676
b0b0dfa
3ff4083
f8ab7f0
6f857f6
1f9e7b4
d9fe492
8c9fa30
e586b20
8938cfc
654d495
05ec36a
5620c8c
35ad4a7
6b59a9e
fbf46da
216a1ff
07c7f8d
508d5a7
757ff8e
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,5 @@ | ||
| build | ||
| build-asan | ||
| .vscode | ||
| main | ||
| main.cpp |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| #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,53 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <locale> | ||
|
|
||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| // pos - позиция в массиве array без дубликатов | ||
| size_t pos = 0; | ||
|
|
||
| // size - размер массива с учётом '\0' в конце | ||
| for (size_t i = 0; i < size - 1; ++i) { | ||
| // сохраняем символ до его замены и приводим его к uint | ||
| // функции isdigit, islower и др. не работают с отрицательным кодами | ||
| char old_symbol = static_cast<unsigned int>(array[i]); | ||
|
|
||
| // определяем тип замены | ||
| if (isdigit(old_symbol)) { | ||
| array[pos++] = '*'; | ||
| } | ||
| else if (old_symbol == ' ') { | ||
| array[pos++] = delimiter; | ||
| } | ||
| else if (islower(old_symbol)) { | ||
| array[pos++] = toupper(old_symbol); | ||
| } | ||
| else if (isupper(old_symbol)) { | ||
| array[pos++] = old_symbol; | ||
| } | ||
| else { | ||
| array[pos++] = '_'; | ||
| } | ||
|
|
||
| // поиск и подсчёт дубликатов | ||
| size_t j = i + 1; | ||
| while (j < size && array[j] == old_symbol) { | ||
| ++j; | ||
| } | ||
|
|
||
| // если есть дубликаты | ||
| if (size_t duplicates = j - i - 1; duplicates > 0) { | ||
| // обновляем указатель i | ||
| i += duplicates; | ||
|
|
||
| // добавляем счётчик после повторяющегося символа (кроме ' ') | ||
| if (old_symbol != ' ') | ||
| array[pos++] = duplicates + 1 >= 10 ? '0' : duplicates + 1 + '0'; | ||
| } | ||
| } | ||
|
|
||
| // устанавливаем новый конец массива | ||
| array[pos] = '\0'; | ||
|
|
||
| return pos; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #include <cstdint> | ||
| #include <stdexcept> | ||
|
|
||
| #include <string> | ||
| #include <utility> | ||
| #include <iostream> | ||
|
|
||
| enum class CheckFlags : uint8_t { | ||
| NONE = 0, | ||
|
|
@@ -13,6 +14,40 @@ enum class CheckFlags : uint8_t { | |
| ALL = TIME | DATE | USER | CERT | KEYS | DEST | ||
| }; | ||
|
|
||
| CheckFlags operator&(CheckFlags lhs, CheckFlags rhs) { | ||
| return static_cast<CheckFlags>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs)); | ||
| } | ||
|
|
||
| void PrintCheckFlags(CheckFlags flags) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| // Проверка на выход за диапозон значений CheckFlags | ||
| if ((~static_cast<uint8_t>(CheckFlags::ALL) & static_cast<uint8_t>(flags)) != 0) { | ||
| return; | ||
| } | ||
|
|
||
| const static std::pair<CheckFlags, std::string> checks[] { | ||
| {CheckFlags::TIME, "TIME"}, | ||
| {CheckFlags::DATE, "DATE"}, | ||
| {CheckFlags::USER, "USER"}, | ||
| {CheckFlags::CERT, "CERT"}, | ||
| {CheckFlags::KEYS, "KEYS"}, | ||
| {CheckFlags::DEST, "DEST"} | ||
| }; | ||
|
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. выглядит не очень эффективно, каждый раз создавать вектор |
||
|
|
||
| bool first = true; | ||
|
|
||
| std::cout << "["; | ||
|
|
||
| for (const auto& [flag, name] : checks) { | ||
| if ((flags & flag) != CheckFlags::NONE) { | ||
| if (first) { | ||
| first = false; | ||
| } | ||
| else { | ||
| std::cout << ","; | ||
| } | ||
| std::cout << name; | ||
| } | ||
| } | ||
|
|
||
| std::cout << ']'; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| namespace { | ||
| constexpr long double INCHES_PER_FOOT = 12.0L; | ||
| constexpr long double CM_PER_INCH = 2.54L; | ||
| constexpr long double M_PER_FOOT = 0.3048L; | ||
| constexpr long double CM_PER_FOOT = M_PER_FOOT * 100.0L; | ||
| constexpr long double M_PER_INCH = CM_PER_INCH / 100.0L; | ||
| constexpr long double CM_PER_METER = 100.0L; | ||
| } | ||
|
|
||
| // ==== Перевод футов ==== | ||
| constexpr long double operator""_ft_to_m(long double ft) { | ||
| return ft * M_PER_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_ft_to_cm(long double ft) { | ||
| return ft * CM_PER_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_ft_to_in(long double ft) { | ||
| return ft * INCHES_PER_FOOT; | ||
| } | ||
|
|
||
| // ==== Перевод дюймов ==== | ||
| constexpr long double operator""_in_to_m(long double in) { | ||
| return in * M_PER_INCH; | ||
| } | ||
|
|
||
| constexpr long double operator""_in_to_cm(long double in) { | ||
| return in * CM_PER_INCH; | ||
| } | ||
|
|
||
| constexpr long double operator""_in_to_ft(long double in) { | ||
| return in / INCHES_PER_FOOT; | ||
| } | ||
|
|
||
| // ==== Перевод метров ==== | ||
| constexpr long double operator""_m_to_ft(long double m) { | ||
| return m / M_PER_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_m_to_in(long double m) { | ||
| return m / M_PER_INCH; | ||
| } | ||
|
|
||
| constexpr long double operator""_m_to_cm(long double m) { | ||
| return m * CM_PER_METER; | ||
| } | ||
|
|
||
| // ==== Перевод сантиметров ==== | ||
| constexpr long double operator""_cm_to_m(long double cm) { | ||
| return cm / CM_PER_METER; | ||
| } | ||
|
|
||
| constexpr long double operator""_cm_to_ft(long double cm) { | ||
| return cm / CM_PER_FOOT; | ||
| } | ||
|
|
||
| constexpr long double operator""_cm_to_in(long double cm) { | ||
| return cm / CM_PER_INCH; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,22 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <stddef.h> | ||
| #include <iostream> | ||
|
|
||
|
|
||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| size_t bits = bytes * 8; | ||
| unsigned long long bit_index = 1ll << (bits - 1); // 0b1000'...'0000 | ||
| size_t delims = 1 + 2 * (bytes - 1); | ||
| // Выделяем буфер под биты, апострофы и '\0' в конце | ||
| size_t buffer_size = bits + delims + 1; | ||
|
|
||
| std::cout << "0b"; | ||
| for (size_t i = 0; i < buffer_size - 1; ++i) { | ||
| if (i % 5 == 4) { | ||
| std::cout << '\''; | ||
| } else { | ||
| std::cout << static_cast<char>(static_cast<bool>(value & bit_index) + '0'); | ||
| bit_index = bit_index >> 1; | ||
| } | ||
| } | ||
| std::cout << std::endl; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,37 @@ | ||
| #include <stdexcept> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <cmath> | ||
|
|
||
|
|
||
| void SolveQuadratic(int a, int b, int c) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if (a == 0 && b == 0 && c == 0) { | ||
| std::cout << "infinite solutions"; | ||
| return; | ||
| } | ||
|
|
||
| if (a == 0) { | ||
|
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. надо приводить к единому стилю, тогда выше должна тоже быть проверка на 0, если это число принято проводить првоерку сравнением, а форма !ptr, как правило используется для указателей |
||
| b != 0 ? std::cout << -(static_cast<double>(c) / b) : std::cout << "no solutions"; | ||
| return; | ||
| } | ||
|
|
||
| if (b == 0 && c == 0) { | ||
| std::cout << 0; | ||
| return; | ||
| } | ||
|
|
||
| double discriminant = static_cast<double>(b) * b - 4.0 * a * c; | ||
|
|
||
| if (discriminant > 0) { | ||
| double sqrt_d = std::sqrt(discriminant); | ||
| double x1 = (-b - sqrt_d) / (2.0 * a); | ||
| double x2 = (-b + sqrt_d) / (2.0 * a); | ||
| std::cout << std::setprecision(6) << x1 << ' ' << x2; | ||
| } | ||
| else if (discriminant == 0) { | ||
| double x = -b / (2.0 * a); | ||
| std::cout << std::setprecision(6) << x; | ||
| } | ||
| else { | ||
| std::cout << "no solutions"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| #include <cstdef> | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
|
|
||
|
|
||
| double CalculateRMS(double values[], size_t size) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if (size == 0 || values == nullptr) return .0; | ||
|
|
||
| double result = 0; | ||
| for (size_t i = 0; i < size; ++i) { | ||
| result += values[i]*values[i]; | ||
| } | ||
|
|
||
| // size неявно преобразуется к double | ||
| return std::sqrt(result / size); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| #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 (*func_arr[])(double, double), size_t size) { | ||
| if (size == 0) return 0; | ||
|
|
||
| double result = 0; | ||
|
|
||
| for (size_t i = 0; i < size; ++i) { | ||
| if (func_arr[i]) | ||
| result += func_arr[i](a, b); | ||
| } | ||
|
|
||
| return result; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,30 @@ | ||
| #include <stdexcept> | ||
| #include <cstddef> | ||
|
|
||
| const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(int)) { | ||
| if (!begin || !end || !predicate || begin > end) | ||
| return end; | ||
|
|
||
| /* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| const int* last = end; | ||
|
|
||
| for (; begin < end; ++begin) { | ||
| if (predicate(*begin)) { | ||
| last = begin; | ||
| } | ||
| } | ||
|
|
||
| return last; | ||
| } | ||
|
|
||
| int* FindLastElement(int* begin, int* end, bool (*predicate)(int)) { | ||
| return const_cast<int*>( | ||
| FindLastElement( | ||
| const_cast<const int*>(begin), | ||
| const_cast<const int*>(end), | ||
| predicate | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| inline int* FindLastElement(std::nullptr_t, std::nullptr_t, bool (*)(int)) { | ||
| return nullptr; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,24 @@ | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
|
|
||
| void PrintMemory(const u_char* begin, size_t size, bool is_little_endian) { | ||
| const u_char* end = begin + size; | ||
|
|
||
| void PrintMemory(int /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| std::cout << "0x" << std::hex << std::uppercase; | ||
| for ( | ||
| const u_char* ptr = is_little_endian ? end - 1 : begin; | ||
| is_little_endian ? ptr >= begin : ptr < end; | ||
| is_little_endian ? --ptr : ++ptr | ||
| ) { | ||
| std::cout << std::setfill('0') << std::setw(2) << static_cast<int>(*ptr); | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| void PrintMemory(double /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| void PrintMemory(int num, bool is_little_endian = false) { | ||
| PrintMemory(reinterpret_cast<u_char*>(&num), sizeof(num), is_little_endian); | ||
| } | ||
|
|
||
| void PrintMemory(double num, bool is_little_endian = false) { | ||
| PrintMemory(reinterpret_cast<u_char*>(&num), sizeof(num), is_little_endian); | ||
| } |
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.
много лишних комментариев