-
Notifications
You must be signed in to change notification settings - Fork 33
Милов Виктор #31
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?
Милов Виктор #31
Changes from all commits
ce68541
5e04fb1
6c6fa03
b1e00ef
5f38c89
58447fc
f925abb
9cdb471
8c07ce0
d810d45
0a68971
b28a186
93e9601
781c3d4
d91ae68
8ae3194
dafec21
0661033
766ddba
1d7ea6e
6aab29a
550a58a
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| #include <cstdint> | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| int64_t Addition(int a, int b) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| 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,111 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cctype> | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') | ||
| { | ||
| // throw std::runtime_error{"Not implemented"}; | ||
| size_t j = 0; | ||
| size_t i = 0; | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| while (i < size && array[i] != '\0') | ||
| { | ||
| if (array[i] == ' ') | ||
| { | ||
| // Пропускаем все пробелы | ||
| size_t spaces = 0; | ||
| while (i < size && array[i] == ' ') | ||
| { | ||
| i++; | ||
| spaces++; | ||
| } | ||
|
|
||
| // Записываем разделитель если есть пробелы | ||
| if (spaces > 0) | ||
| { | ||
| if (j < size - 1) | ||
| { | ||
| array[j] = delimiter; | ||
| j++; | ||
| } | ||
| else | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // Определяем длину последовательности одинаковых символов | ||
| char original = array[i]; | ||
| size_t count = 0; | ||
| while (i + count < size && array[i + count] == original && array[i + count] != '\0') | ||
| { | ||
| count++; | ||
| } | ||
|
|
||
| // Преобразуем символ | ||
| char current = original; | ||
| if (std::isdigit(static_cast<unsigned char>(original))) | ||
| { | ||
| current = '*'; | ||
| } | ||
| else if (std::islower(static_cast<unsigned char>(original))) | ||
| { | ||
| current = std::toupper(static_cast<unsigned char>(original)); | ||
| } | ||
| else if (!std::isupper(static_cast<unsigned char>(original))) | ||
| { | ||
| current = '_'; | ||
| } | ||
|
|
||
| // Записываем результат с учетом правила повторений | ||
| if (count == 1) | ||
| { | ||
| if (j < size - 1) | ||
| { | ||
| array[j] = current; | ||
| j++; | ||
| } | ||
| else | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (j + 1 < size - 1) | ||
| { | ||
| array[j] = current; | ||
| if (count >= 10) | ||
| { | ||
| array[j + 1] = '0'; | ||
| } | ||
| else | ||
| { | ||
| array[j + 1] = '0' + count; | ||
| } | ||
| j += 2; | ||
| } | ||
| else | ||
| { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| i += count; | ||
| } | ||
| } | ||
|
|
||
| // Завершаем строку | ||
| if (j < size) | ||
| { | ||
| array[j] = '\0'; | ||
| } | ||
| else if (size > 0) | ||
| { | ||
| array[size - 1] = '\0'; | ||
| } | ||
|
|
||
| return j; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| #include <cstdint> | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
|
|
||
| enum class CheckFlags : uint8_t { | ||
| enum class CheckFlags : uint8_t | ||
| { | ||
| NONE = 0, | ||
| TIME = (1 << 0), | ||
| DATE = (1 << 1), | ||
|
|
@@ -13,6 +15,54 @@ 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) | ||
| { | ||
| // throw std::runtime_error{"Not implemented"}; | ||
| uint8_t value = static_cast<uint8_t>(flags); | ||
|
|
||
| // Проверка на выход за диапазон | ||
| if (value > static_cast<uint8_t>(CheckFlags::ALL)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| std::vector<std::string> active_flags; | ||
|
|
||
| // Проверяем каждый флаг в правильном порядке | ||
| if (value & static_cast<uint8_t>(CheckFlags::TIME)) | ||
| { | ||
| active_flags.push_back("TIME"); | ||
| } | ||
| if (value & static_cast<uint8_t>(CheckFlags::DATE)) | ||
| { | ||
| active_flags.push_back("DATE"); | ||
| } | ||
| if (value & static_cast<uint8_t>(CheckFlags::USER)) | ||
| { | ||
| active_flags.push_back("USER"); | ||
| } | ||
| if (value & static_cast<uint8_t>(CheckFlags::CERT)) | ||
| { | ||
| active_flags.push_back("CERT"); | ||
| } | ||
| if (value & static_cast<uint8_t>(CheckFlags::KEYS)) | ||
| { | ||
| active_flags.push_back("KEYS"); | ||
| } | ||
| if (value & static_cast<uint8_t>(CheckFlags::DEST)) | ||
| { | ||
| active_flags.push_back("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. не оптимальное решение, создаем зачем-то вектор строк, с реалокациями памяти |
||
| // Формируем вывод | ||
| std::cout << "["; | ||
| for (size_t i = 0; i < active_flags.size(); ++i) | ||
| { | ||
| if (i > 0) | ||
| { | ||
| std::cout << ","; | ||
| } | ||
| std::cout << active_flags[i]; | ||
| } | ||
| std::cout << "]"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| #include <cmath> | ||
|
|
||
| // Константы преобразования | ||
| constexpr double FEET_TO_METERS = 0.3048; | ||
| constexpr double INCHES_TO_METERS = 0.0254; | ||
| constexpr double METERS_TO_FEET = 1.0 / FEET_TO_METERS; | ||
| constexpr double METERS_TO_INCHES = 1.0 / INCHES_TO_METERS; | ||
| constexpr double FEET_TO_INCHES = 12.0; | ||
| constexpr double INCHES_TO_FEET = 1.0 / FEET_TO_INCHES; | ||
| constexpr double METERS_TO_CM = 100.0; | ||
| constexpr double CM_TO_METERS = 0.01; | ||
|
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. не уверен что нужно столько констант, достаточно бы было 3, где-то можно было бы делить прям в выражениях. также желательно добавить их в безымянный namespace или пометить static |
||
|
|
||
| // Футы в другие единицы | ||
| constexpr double operator"" _ft_to_m(long double feet) | ||
| { | ||
| return feet * FEET_TO_METERS; | ||
| } | ||
|
|
||
| constexpr double operator"" _ft_to_cm(long double feet) | ||
| { | ||
| return feet * FEET_TO_METERS * METERS_TO_CM; | ||
| } | ||
|
|
||
| constexpr double operator"" _ft_to_in(long double feet) | ||
| { | ||
| return feet * FEET_TO_INCHES; | ||
| } | ||
|
|
||
| // Дюймы в другие единицы | ||
| constexpr double operator"" _in_to_m(long double inches) | ||
| { | ||
| return inches * INCHES_TO_METERS; | ||
| } | ||
|
|
||
| constexpr double operator"" _in_to_cm(long double inches) | ||
| { | ||
| return inches * INCHES_TO_METERS * METERS_TO_CM; | ||
| } | ||
|
|
||
| constexpr double operator"" _in_to_ft(long double inches) | ||
| { | ||
| return inches * INCHES_TO_FEET; | ||
| } | ||
|
|
||
| // Метры в другие единицы | ||
| constexpr double operator"" _m_to_ft(long double meters) | ||
| { | ||
| return meters * METERS_TO_FEET; | ||
| } | ||
|
|
||
| constexpr double operator"" _m_to_in(long double meters) | ||
| { | ||
| return meters * METERS_TO_INCHES; | ||
| } | ||
|
|
||
| constexpr double operator"" _m_to_cm(long double meters) | ||
| { | ||
| return meters * METERS_TO_CM; | ||
| } | ||
|
|
||
| // Сантиметры в другие единицы | ||
| constexpr double operator"" _cm_to_m(long double centimeters) | ||
| { | ||
| return centimeters * CM_TO_METERS; | ||
| } | ||
|
|
||
| constexpr double operator"" _cm_to_ft(long double centimeters) | ||
| { | ||
| return centimeters * CM_TO_METERS * METERS_TO_FEET; | ||
| } | ||
|
|
||
| constexpr double operator"" _cm_to_in(long double centimeters) | ||
| { | ||
| return centimeters * CM_TO_METERS * METERS_TO_INCHES; | ||
| } | ||
|
|
||
| // Перегрузки для целочисленных литералов | ||
| constexpr double operator"" _ft_to_m(unsigned long long feet) | ||
| { | ||
| return static_cast<double>(feet) * FEET_TO_METERS; | ||
| } | ||
|
|
||
| constexpr double operator"" _ft_to_cm(unsigned long long feet) | ||
| { | ||
| return static_cast<double>(feet) * FEET_TO_METERS * METERS_TO_CM; | ||
| } | ||
|
|
||
| constexpr double operator"" _ft_to_in(unsigned long long feet) | ||
| { | ||
| return static_cast<double>(feet) * FEET_TO_INCHES; | ||
| } | ||
|
|
||
| constexpr double operator"" _in_to_m(unsigned long long inches) | ||
| { | ||
| return static_cast<double>(inches) * INCHES_TO_METERS; | ||
| } | ||
|
|
||
| constexpr double operator"" _in_to_cm(unsigned long long inches) | ||
| { | ||
| return static_cast<double>(inches) * INCHES_TO_METERS * METERS_TO_CM; | ||
| } | ||
|
|
||
| constexpr double operator"" _in_to_ft(unsigned long long inches) | ||
| { | ||
| return static_cast<double>(inches) * INCHES_TO_FEET; | ||
| } | ||
|
|
||
| constexpr double operator"" _m_to_ft(unsigned long long meters) | ||
| { | ||
| return static_cast<double>(meters) * METERS_TO_FEET; | ||
| } | ||
|
|
||
| constexpr double operator"" _m_to_in(unsigned long long meters) | ||
| { | ||
| return static_cast<double>(meters) * METERS_TO_INCHES; | ||
| } | ||
|
|
||
| constexpr double operator"" _m_to_cm(unsigned long long meters) | ||
| { | ||
| return static_cast<double>(meters) * METERS_TO_CM; | ||
| } | ||
|
|
||
| constexpr double operator"" _cm_to_m(unsigned long long centimeters) | ||
| { | ||
| return static_cast<double>(centimeters) * CM_TO_METERS; | ||
| } | ||
|
|
||
| constexpr double operator"" _cm_to_ft(unsigned long long centimeters) | ||
| { | ||
| return static_cast<double>(centimeters) * CM_TO_METERS * METERS_TO_FEET; | ||
| } | ||
|
|
||
| constexpr double operator"" _cm_to_in(unsigned long long centimeters) | ||
| { | ||
| return static_cast<double>(centimeters) * CM_TO_METERS * METERS_TO_INCHES; | ||
| } | ||
|
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. много лишнего кода, если у нас возвращается double то зачем целочисленный вариант |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,51 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
|
|
||
| void PrintBits(long long value, size_t bytes) | ||
| { | ||
| // throw std::runtime_error{"Not implemented"}; | ||
| // Проверяем допустимость размера | ||
| if (bytes == 0 || bytes > 8) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| // Вычисляем общее количество битов | ||
| size_t total_bits = bytes * 8; | ||
|
|
||
| // Создаем маску для извлечения нужного количества байтов | ||
| unsigned long long mask = 0; | ||
| if (bytes == 8) | ||
| { | ||
| mask = ~0ULL; // Все биты установлены в 1 | ||
| } | ||
| else | ||
| { | ||
| mask = (1ULL << total_bits) - 1; | ||
| } | ||
|
|
||
| // Приводим значение к беззнаковому типу и применяем маску | ||
|
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. буквально это же написано строкой ниже, это излишний комментарий |
||
| unsigned long long unsigned_value = static_cast<unsigned long long>(value); | ||
| unsigned_value &= mask; | ||
|
|
||
| // Выводим префикс | ||
|
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. много лишних комментариев в коде |
||
| std::cout << "0b"; | ||
|
|
||
| // Выводим биты группами по 4 | ||
| for (int i = static_cast<int>(total_bits) - 1; i >= 0; 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. префиксный декремент должен быть |
||
| { | ||
| // Получаем текущий бит | ||
| unsigned long long bit = (unsigned_value >> i) & 1; | ||
| std::cout << (bit ? '1' : '0'); | ||
|
|
||
| // Добавляем апостроф после каждой группы из 4 битов (кроме последней) | ||
| if (i > 0 && i % 4 == 0) | ||
| { | ||
| std::cout << "'"; | ||
| } | ||
| } | ||
|
|
||
| // Завершаем вывод переводом строки | ||
| std::cout << "\n"; | ||
| } | ||
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.
префиксные инкрименты лучше использовать