-
Notifications
You must be signed in to change notification settings - Fork 33
Еремин Даниил #36
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
Open
18thday
wants to merge
45
commits into
psds-cpp:main
Choose a base branch
from
RIZONTE:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Еремин Даниил #36
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
31ce710
Тестовый коммит. Addition
RIZONTE f299b48
add solution: add addition task
RIZONTE b31a9d1
add (github): add testing action
RIZONTE 643d325
fix (solution): Ошибка в директиве include
RIZONTE 9744f6e
Merge branch 'main' of github.com:RIZONTE/psds-cpp-2025
RIZONTE 48d2baf
add (solution): Решены задачи rms и char_changer
RIZONTE be553da
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE 852bf3a
add (solution): Решение Check_flags
RIZONTE d704a5e
modify (solution): Добавил комментарии в check_flags.cpp
RIZONTE 4ef2338
add (solution): Добавлено решение length_lit
RIZONTE afc1d22
add (solution): Решение print_bits
RIZONTE 2b41f11
add (solution): Решение quadratic
RIZONTE af33200
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE 5eddea2
add (solution): Решение func_array
RIZONTE be140db
add (solution): Решение last_of_us
RIZONTE d57c94c
add (solution): Решение little_big
RIZONTE 0e3b4bf
add (solution): Решение longest
RIZONTE 6779b17
modify (solution): Добавил константность итератору в for
RIZONTE e61c5b9
add (solution): Решение pretty_array
RIZONTE 7370299
add (solution): Решение swap_ptr
RIZONTE b7cb116
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE 280c7d6
add (solution): Решение data_stats
RIZONTE 067405d
add (solution): Решение easy_compare
RIZONTE bc3dc9b
add (solution): Решение enum_operators
RIZONTE 6e34b9c
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE ce86dd7
modify (CMakeList): Закомментировал строчку в 4-й неделе, чтобы собир…
RIZONTE ea262f1
add (solution): Решение filter
RIZONTE 7d1d00b
add (solution): Решение find_all
RIZONTE 67e42d0
add (solution): Решение minmax
RIZONTE c46016a
add (solution): Решение os_overload
RIZONTE 1b359da
add (solution): Решение range
RIZONTE c06738d
add (solution): Решение unique
RIZONTE 01adc7e
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE 92d14f4
add (solution): Решение phasor, проходит первые 11 тестов
RIZONTE 87cab48
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE 30bd518
add (solution): Решение phasor
RIZONTE ac16b5b
add (solution): Решение queue
RIZONTE 795eb5b
add (solution): Решение ring_buffer(такое себе решение)
RIZONTE a78c741
add (solution): Решение stack
RIZONTE 2796646
modify (solution): Исправления в queue, названия полей класса
RIZONTE 440ba29
modify (solution): Исправление замечаний 1-й недели
RIZONTE e1bbc8e
modify (solution): Исправление замечаний 2-й недели
RIZONTE a8cc8e2
modify (solutions): Исправление замечаний 3-й недели, частично
RIZONTE 4c1b18c
Merge branch 'main' of https://github.com/psds-cpp/psds-cpp-2025
RIZONTE c13e68d
add (solution): Решение tracer
RIZONTE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| build/ | ||
| .vs/ | ||
| CMakeLists.txt.user | ||
| CMakeSettings.json | ||
| CMakeUserPresets.json | ||
| .vscode/ | ||
| *.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,54 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cctype> | ||
|
|
||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| //Массив для подстановки кол-ва повторений | ||
| char intToChar[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; | ||
|
|
||
| size_t i = 0; | ||
| size_t j = 1; | ||
| size_t str_end = 0; | ||
|
|
||
| int reps = 1; // кол-во повторений символа | ||
| while (j < size) { | ||
| if (array[i] == array[j]) { | ||
| ++reps; | ||
| ++j; | ||
| continue; | ||
| } | ||
|
|
||
| array[str_end] = array[i]; | ||
| if (reps != 1 && array[i] != ' ') { | ||
| array[str_end+1] = reps < 10 ? intToChar[reps] : intToChar[0]; | ||
| } | ||
|
|
||
| if (char c = array[str_end]; std::isalpha(c) && std::islower(c)) { | ||
| array[str_end] = std::toupper(c); | ||
| } | ||
| else if (array[str_end] == ' ') { | ||
| array[str_end] = delimiter; | ||
| ++str_end; | ||
| i = j++; | ||
| reps = 1; | ||
| continue; | ||
| } | ||
| else if (std::isdigit(array[str_end])) { | ||
| array[str_end] = '*'; | ||
| } | ||
| else if (!(std::isalpha(array[str_end]))) { | ||
| array[str_end] = '_'; | ||
| } | ||
|
|
||
| if (reps == 1) { | ||
| ++str_end; | ||
| } | ||
| else { | ||
| str_end+= 2; | ||
| reps = 1; | ||
| } | ||
| i = j++; | ||
| } | ||
| array[str_end] = '\0'; | ||
| return str_end; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| namespace { | ||
| constexpr double IN_IN_FT = 12.0; //дюймов в футе | ||
| constexpr double CM_IN_FT = 30.48; //сантиметров в футе | ||
| constexpr double CM_IN_M = 100; //сантиметров в метре | ||
| constexpr double CM_IN_IN = 2.54; //сантиметров в дюйме | ||
| } | ||
|
|
||
| //Футы в дюймы | ||
| constexpr double operator""_ft_to_in(long double ft) { | ||
| return ft * IN_IN_FT; | ||
| } | ||
|
|
||
| //Футы в сантиметры | ||
| constexpr double operator""_ft_to_cm(long double ft) { | ||
| return ft * CM_IN_FT; | ||
| } | ||
|
|
||
| //Футы в метры | ||
| constexpr double operator""_ft_to_m(long double ft) { | ||
| return (ft * CM_IN_FT) / CM_IN_M; | ||
| } | ||
|
|
||
| //Дюймы в футы | ||
| constexpr double operator""_in_to_ft(long double in) { | ||
| return in / IN_IN_FT; | ||
| } | ||
|
|
||
| //Дюймы в сантиметры | ||
| constexpr double operator""_in_to_cm(long double in) { | ||
| return in * CM_IN_IN; | ||
| } | ||
|
|
||
| //Дюймы в метры | ||
| constexpr double operator""_in_to_m(long double in) { | ||
| return (in * CM_IN_IN) / CM_IN_M; | ||
| } | ||
|
|
||
| //Сантиметры в футы | ||
| constexpr double operator""_cm_to_ft(long double cm) { | ||
| return cm / CM_IN_FT; | ||
| } | ||
|
|
||
| //Сантиметры в дюймы | ||
| constexpr double operator""_cm_to_in(long double cm) { | ||
| return cm / CM_IN_IN; | ||
| } | ||
|
|
||
| //Сантиметры в метры | ||
| constexpr double operator""_cm_to_m(long double cm) { | ||
| return cm / CM_IN_M; | ||
| } | ||
|
|
||
| //Метры в футы | ||
| constexpr double operator""_m_to_ft(long double m) { | ||
| return (m * CM_IN_M) / CM_IN_FT; | ||
| } | ||
|
|
||
| //Метры в дюймы | ||
| constexpr double operator""_m_to_in(long double m) { | ||
| return (m * CM_IN_M) / CM_IN_IN; | ||
| } | ||
|
|
||
| //Метры в сантиметры | ||
| constexpr double operator""_m_to_cm(long double m) { | ||
| return m * CM_IN_M; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
|
|
||
| #include <iostream> | ||
|
|
||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| size_t bitLen = 8 * bytes; | ||
|
|
||
| std::cout << "0b"; | ||
| for (size_t i = bitLen - 1; i < bitLen; --i) { | ||
| std::cout << ((value >> i) % 2 == 0 ? '0' : '1'); | ||
| if (i != 0 && i % 4 == 0) { | ||
| std::cout << '\''; | ||
| } | ||
| } | ||
|
|
||
| std::cout << "\n"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,42 @@ | ||
| #include <stdexcept> | ||
|
|
||
| #include <iostream> | ||
| #include <iomanip> | ||
| #include <cmath> | ||
|
|
||
| void SolveQuadratic(int a, int b, int c) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| //Установка точности вывода в 6 символов | ||
| std::cout << std::setprecision(6); | ||
|
|
||
| double eps = 1e-3; // Погрешность при сравнении double | ||
| double x1{0}, x2{0}; | ||
| if (a == 0 && b == 0 && c != 0) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
| if (a == 0 && b == 0 && c == 0) { | ||
| std::cout << "infinite solutions"; | ||
| return; | ||
| } | ||
| if(b != 0 && a == 0){ | ||
| x1 = -c / static_cast<double>(b); | ||
| std::cout << x1; | ||
| return; | ||
| } | ||
|
|
||
| long long d = static_cast<long long>(b) * b - 4 * static_cast<long long>(a) * c; | ||
| if(d < 0){ | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
|
|
||
| x1 = (-b + sqrt(d)) / (2*a); | ||
| x2 = (-b - sqrt(d)) / (2*a); | ||
| if((x1 - x2) < eps){ | ||
| std::cout << x1; | ||
| } | ||
| else{ | ||
| if(x1 > x2){ | ||
| std::swap(x1, x2); | ||
| } | ||
| std::cout << x1 << " " << x2; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| #include <cstdef> | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
|
|
||
|
|
||
| double CalculateRMS(double values[], size_t size) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if(values == nullptr || size == 0){ | ||
| return 0.0; | ||
| } | ||
|
|
||
| double res {0.0}; | ||
| for(size_t i = 0; i < size; ++i){ | ||
| res += values[i] * values[i]; | ||
| } | ||
| return std::sqrt(res / size); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| #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 (**functions)(double, double), size_t size) { | ||
| if(size == 0) return 0.0; | ||
|
|
||
| double res{}; | ||
| for(size_t i = 0; i < size; ++i){ | ||
| res += !functions[i] ? 0.0 : functions[i](a, b); | ||
| } | ||
|
|
||
| return res; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| #include <stdexcept> | ||
|
|
||
| const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(int)) { | ||
| if(begin == nullptr || end == nullptr || begin > end) return end; | ||
|
|
||
| /* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| for(const int* current = (end-1); current != begin-1; --current){ | ||
| if(predicate(*current)) return current; | ||
| } | ||
| return end; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,28 @@ | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
| #include <cstddef> | ||
| #include <iomanip> | ||
|
|
||
| void PrintHex(const unsigned char* ptr, const size_t size, bool inverse) { | ||
| for (size_t i = 0; i < size; ++i) { | ||
| std::cout << std::uppercase << std::hex << std::setw(2) << std::setfill('0') | ||
| << (!inverse ? static_cast<unsigned int>(ptr[i]) : static_cast<unsigned int>(ptr[size - 1 - i])); | ||
| } | ||
| } | ||
|
|
||
| void PrintMemory(int /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void PrintMemory(int num, bool inverse = false) { | ||
| const size_t size = sizeof(int); | ||
| auto ptr = reinterpret_cast<const unsigned char*>(&num); | ||
|
|
||
| std::cout << "0x"; | ||
| PrintHex(ptr, size, inverse); | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| void PrintMemory(double /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void PrintMemory(double num, bool inverse = false) { | ||
| const size_t size = sizeof(double); | ||
| auto ptr = reinterpret_cast<const unsigned char*>(&num); | ||
|
|
||
| std::cout << "0x"; | ||
| PrintHex(ptr, size, inverse); | ||
| std::cout << std::endl; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,29 @@ | ||
| #include <stdexcept> | ||
| #include <cstddef> | ||
|
|
||
| const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) { | ||
| const char* res{nullptr}; | ||
| count = 0; | ||
|
|
||
| /* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if(begin == nullptr || end == nullptr) return nullptr; | ||
|
|
||
| size_t curLen{1}; | ||
| const char* curBegin{begin}; | ||
| for(const char* curent = begin; curent < end; ++curent){ | ||
| if(curent+1 != end && *curent == *(curent+1)){ | ||
| curBegin = curLen == 1 ? curent : curBegin; | ||
| ++curLen; | ||
| continue; | ||
| } | ||
|
|
||
| res = count < curLen ? curBegin : res; | ||
| count = count < curLen ? curLen : count; | ||
| curLen = 1; | ||
| } | ||
|
|
||
| return res; | ||
| } | ||
|
|
||
| char* FindLongestSubsequence(char* begin, char* end, size_t& count) { | ||
| const char* const_res = FindLongestSubsequence(const_cast<const char*>(begin), const_cast<const char*>(end), count); | ||
| return const_cast<char*>(const_res); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,25 @@ | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
|
|
||
|
|
||
| void PrintArray(/* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void PrintArray(const int* begin, const int* end, size_t limit = 0) { | ||
| if(begin == nullptr || end == nullptr) { | ||
| std::cout << "[]\n"; | ||
| return; | ||
| } | ||
|
|
||
| std::cout << "["; | ||
| int step = begin > end ? -1 : 1; | ||
| size_t i = 1; | ||
| for(const int* curent = begin; curent != end; curent += step) { | ||
| if(limit != 0 && i > limit) { | ||
| std::cout << "...\n " << *curent << (curent+step == end ? "" : ", "); | ||
| i = 1; | ||
| } | ||
| else { | ||
| std::cout << *curent << (curent+step == 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. практически полное дублирование кода, можнобыло например по условию определить шаг и потом шагать с этим шагом, используя один for, и переписав немного логику |
||
| ++i; | ||
| } | ||
|
|
||
| std::cout << "]\n"; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
идет полное дублирование кода, после получения указателя и, зная sizeof типа num, можно было вызвать третью функцию без дублирования кода