-
Notifications
You must be signed in to change notification settings - Fork 33
Тутынина Полина #35
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?
Тутынина Полина #35
Changes from all commits
44b09fc
7d9c0dd
cb946d9
94303df
ca2154d
ef5b8ea
f189669
1c58aed
2da7917
4240c90
3a5c4ca
11b8a81
eac2189
b1cb4fa
ddbe982
8a09583
56b23ff
2aa9b6c
3ca1f95
c7622ed
c4e4c68
651d799
9370099
1d4b6a0
fd5954d
baf58b9
fe298d8
b9ba25e
60f0a46
e9cd77e
7a56e52
dc72f51
489e21e
b26dd57
242f347
476652f
57da243
618d5e8
453435f
1ce783f
806d00e
5b6643e
4deb0c1
7f0d7e9
5d138c6
e4c03b1
7f6b951
a43ba2d
b1c3d79
082a70d
be4a097
34be524
47c8863
8d94f4e
ce178f3
0dec6e7
be0f5de
d5a943a
dbc02cc
ffc22b2
833b5c9
7b059fc
28e4701
5988c1a
2532416
9b09894
9aa937c
f38590a
7a3a3c3
6a38f83
83d2d16
a23cfaf
d87efd8
5212951
245ab57
2ce8537
2d9231d
6f00132
66194ee
c7c3995
120c237
6fd4b0c
8044070
84904f2
9bc313d
d84a8b1
bab1f41
3110598
5626b1a
c664556
ca5c55b
e3d2953
815d762
68c561d
5737682
97155bb
5fd8081
c4912f8
e813ba7
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,3 @@ | ||
| build-*/ | ||
| a.out | ||
| *.out |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| #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,104 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cctype> | ||
|
|
||
| /* Преобразует строку по правилам: | ||
| - Повторяющиеся символы (кроме пробелов) заменяются на символ+число повторений | ||
| - Цифры заменяются на '*' | ||
| - Все латинские буквы преобразуются в прописные | ||
| - Последовательные пробелы заменяются на разделитель | ||
| - Остальные символы заменяются на '_' | ||
| Возвращает новую длину строки */ | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| size_t CharChanger(char array[], size_t size, char delimiter) { | ||
| if (size == 0) return 0; | ||
|
|
||
| size_t write_pos = 0; | ||
| char prev_char = '\0'; | ||
| char current_sequence_char = '\0'; | ||
| size_t count = 0; | ||
| bool in_space_sequence = false; | ||
|
|
||
| for (size_t read_pos = 0; read_pos < size && array[read_pos] != '\0'; read_pos++) { | ||
|
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. префиксный инкремент нужен |
||
| char current_char = array[read_pos]; | ||
|
|
||
| // Обработка пробелов | ||
| if (current_char == ' ') { | ||
| // Если у нас есть незаписанная последовательность, записываем ее | ||
| if (current_sequence_char != '\0') { | ||
| array[write_pos++] = current_sequence_char; | ||
| if (count > 1) { | ||
| if (count >= 10) { | ||
| array[write_pos++] = '0'; | ||
| } else { | ||
| array[write_pos++] = '0' + count; | ||
| } | ||
| } | ||
| current_sequence_char = '\0'; | ||
| count = 0; | ||
| } | ||
|
|
||
| // Добавляем разделитель для каждой группы пробелов | ||
| if (!in_space_sequence) { | ||
| array[write_pos++] = delimiter; | ||
| in_space_sequence = true; | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| // Не пробел - сбрасываем флаг последовательности пробелов | ||
| in_space_sequence = false; | ||
|
|
||
| // Преобразование символа | ||
| char transformed_char = current_char; | ||
|
|
||
| if (std::isdigit(current_char)) { | ||
| transformed_char = '*'; | ||
| } else if (std::isalpha(current_char)) { | ||
| transformed_char = std::toupper(current_char); | ||
| } else if (current_char != ' ') { | ||
| transformed_char = '_'; | ||
| } | ||
|
|
||
| // Обработка последовательностей символов | ||
| if (current_char == prev_char) { | ||
| 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. префиксный инкремент нужен |
||
| } else { | ||
| // Запись предыдущей последовательности | ||
| if (current_sequence_char != '\0') { | ||
| array[write_pos++] = current_sequence_char; | ||
| if (count > 1) { | ||
| if (count >= 10) { | ||
| array[write_pos++] = '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. это достаточно большая вложенность, обычно от такого можно избавиться |
||
| } else { | ||
| array[write_pos++] = '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. дублирование кода, выше есть точно такой же блок, значит можно было написать оптимальнее, что-то может вынести во вспомогательные функции |
||
| // Начало новой последовательности | ||
| prev_char = current_char; | ||
| current_sequence_char = transformed_char; | ||
| count = 1; | ||
| } | ||
| } | ||
|
|
||
| // Запись последней последовательности (если не пробел) | ||
| if (current_sequence_char != '\0') { | ||
| array[write_pos++] = current_sequence_char; | ||
| if (count > 1) { | ||
| if (count >= 10) { | ||
| array[write_pos++] = '0'; | ||
| } else { | ||
| array[write_pos++] = '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. ещё один повтор |
||
|
|
||
| // Завершение строки | ||
| if (write_pos < size) { | ||
| array[write_pos] = '\0'; | ||
| } else if (size > 0) { | ||
| array[size - 1] = '\0'; | ||
| } | ||
|
|
||
| return write_pos; | ||
| } | ||
| 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, | ||
|
|
@@ -14,5 +15,47 @@ enum class CheckFlags : uint8_t { | |
| }; | ||
|
|
||
| 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; // выход за пределы диапазона - оставляем вывод пустым | ||
|
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. тут по коду понятно, комментарии лишние |
||
| } | ||
|
|
||
| // Если флаг NONE | ||
|
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 (flags == CheckFlags::NONE) { | ||
| std::cout << "[]"; | ||
| return; | ||
| } | ||
|
|
||
| std::vector<std::string> active_flags; | ||
|
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 ((value & static_cast<uint8_t>(CheckFlags::TIME)) != 0) { | ||
| active_flags.push_back("TIME"); | ||
| } | ||
| if ((value & static_cast<uint8_t>(CheckFlags::DATE)) != 0) { | ||
| active_flags.push_back("DATE"); | ||
| } | ||
| if ((value & static_cast<uint8_t>(CheckFlags::USER)) != 0) { | ||
| active_flags.push_back("USER"); | ||
| } | ||
| if ((value & static_cast<uint8_t>(CheckFlags::CERT)) != 0) { | ||
| active_flags.push_back("CERT"); | ||
| } | ||
| if ((value & static_cast<uint8_t>(CheckFlags::KEYS)) != 0) { | ||
| active_flags.push_back("KEYS"); | ||
| } | ||
| if ((value & static_cast<uint8_t>(CheckFlags::DEST)) != 0) { | ||
| active_flags.push_back("DEST"); | ||
| } | ||
|
|
||
| // Вывод | ||
| 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,68 @@ | ||
| #include <cmath> | ||
|
|
||
| // Константы для перевода | ||
| constexpr double CM_IN_METER = 100.0; | ||
| constexpr double METERS_IN_FOOT = 0.3048; | ||
| constexpr double INCHES_IN_FOOT = 12.0; | ||
| constexpr double CM_IN_INCH = 2.54; | ||
|
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 double operator"" _m_to_ft(long double meters) { | ||
| return static_cast<long double>(meters / METERS_IN_FOOT); | ||
| } | ||
|
|
||
| // Метры в дюймы | ||
| constexpr double operator"" _m_to_in(long double meters) { | ||
| return static_cast<double>(meters * CM_IN_METER / CM_IN_INCH); | ||
| } | ||
|
|
||
| // Метры в сантиметры | ||
| constexpr double operator"" _m_to_cm(long double meters) { | ||
| return static_cast<double>(meters * CM_IN_METER); | ||
| } | ||
|
|
||
| // Сантиметры в метры | ||
| constexpr double operator"" _cm_to_m(long double centimeters) { | ||
| return static_cast<long double>(centimeters / CM_IN_METER); | ||
| } | ||
|
|
||
| // Сантиметры в футы | ||
| constexpr double operator"" _cm_to_ft(long double centimeters) { | ||
| return static_cast<double>(centimeters / CM_IN_METER / METERS_IN_FOOT); | ||
| } | ||
|
|
||
| // Сантиметры в дюймы | ||
| constexpr double operator"" _cm_to_in(long double centimeters) { | ||
| return static_cast<double>(centimeters / CM_IN_INCH); | ||
| } | ||
|
|
||
| // Футы в метры | ||
| constexpr double operator"" _ft_to_m(long double feet) { | ||
| return static_cast<double>(feet * METERS_IN_FOOT); | ||
| } | ||
|
|
||
| // Футы в сантиметры | ||
| constexpr double operator"" _ft_to_cm(long double feet) { | ||
| return static_cast<double>(feet * METERS_IN_FOOT * CM_IN_METER); | ||
| } | ||
|
|
||
| // Футы в дюймы | ||
| constexpr double operator"" _ft_to_in(long double feet) { | ||
| return static_cast<double>(feet * INCHES_IN_FOOT); | ||
| } | ||
|
|
||
|
|
||
| // Дюймы в метры | ||
| constexpr double operator"" _in_to_m(long double inches) { | ||
| return static_cast<double>(inches * CM_IN_INCH / CM_IN_METER); | ||
| } | ||
|
|
||
| // Дюймы в сантиметры | ||
| constexpr double operator"" _in_to_cm(long double inches) { | ||
| return static_cast<double>(inches * CM_IN_INCH); | ||
| } | ||
|
|
||
| // Дюймы в футы | ||
| constexpr double operator"" _in_to_ft(long double inches) { | ||
| return static_cast<double>(inches / INCHES_IN_FOOT); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,40 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
|
|
||
| #include <iostream> | ||
|
|
||
| /*функцию, преобразующая целое число | ||
| и размер в байтах и выводит на экран битовое представление числа в формате 0bXXXX'XXXX.*/ | ||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| // Проверка допустимости размера | ||
| if (bytes == 0 || bytes > 8) { | ||
| return; | ||
| } | ||
|
|
||
| // Вывод префикс | ||
| std::cout << "0b"; | ||
|
|
||
| // Цикл по всем битам от старшего к младшему | ||
| for (int byte = bytes - 1; byte >= 0; --byte) { | ||
|
|
||
| // Текущий байт | ||
|
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 char current_byte = (value >> (byte * 8)) & 0xFF; | ||
|
|
||
| // Вывод битов текущего байта | ||
| for (int bit = 7; bit >= 0; --bit) { | ||
| // Текущий бит (7-й бит - старший) | ||
| unsigned char current_bit = (current_byte >> bit) & 1; | ||
| std::cout << (current_bit ? '1' : '0'); | ||
|
|
||
| // Добавление апострофа после 4-го бита в каждом байте | ||
| if (bit == 4) { | ||
| std::cout << "'"; | ||
| } | ||
| } | ||
|
|
||
| // Добавление апострофа между байтами (кроме последнего) | ||
| if (byte > 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.
Лишний каст, второй операнд не следует приводить явно, так как он бы преобразовался с помощью неявного каста. Принято использовать такую возможность и не писать явный каст самостоятельно второй раз