-
Notifications
You must be signed in to change notification settings - Fork 33
Кузнецов Владимир #14
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
vova22013
wants to merge
33
commits into
psds-cpp:main
Choose a base branch
from
vova22013: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
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
dad85a7
Update addition.cpp
vova22013 cd838e2
Update char_changer.cpp
vova22013 e0756b3
Update check_flags.cpp
vova22013 a2df496
Update length_lit.cpp
vova22013 77d65d3
Update print_bits.cpp
vova22013 13ced12
Update quadratic.cpp
vova22013 e1b9360
Update rms.cpp
vova22013 578ce8e
Merge branch 'psds-cpp:main' into main
vova22013 ca41a8c
add (solution): add func_array task, add last_of_us task, add little_…
vova22013 39e864a
add (solution): add swap_ptr task
vova22013 25212e4
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
vova22013 e51b15d
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
vova22013 78eedfd
add (solution): add daata_stats task
vova22013 abd3695
add (solution): add easy_compare task
vova22013 bcdbc84
add (solution): add enum_operators task
vova22013 cd158cf
add (solution): add filter task
vova22013 a2130ad
add (solution): add find_all task
vova22013 4a8e567
add (solution): add minmax task
vova22013 8de38a3
add (solution): add os_overload task
vova22013 fd46bb9
add (solution): add range task
vova22013 685908d
add (solution): add unique task
vova22013 099cfcf
Delete 04_week directory
vova22013 b88738d
add (fix): add easy_compare task
vova22013 5c96344
Merge branch 'main' of github.com:vova22013/psds-cpp-2025
vova22013 dcf12db
Merge branch 'main' of github.com:psds-cpp/psds-cpp-2025
vova22013 c0bf6d8
add (solution): add phasor task
vova22013 4bedb7e
add (solution): add queue task
vova22013 8392551
add (solution): add ring_buffer task
vova22013 96da6a7
add (solution): add stack task
vova22013 ec1437a
fix error
vova22013 13d548b
fix errors
vova22013 a2a8659
fix errors
vova22013 658d756
fix errors
vova22013 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 |
|---|---|---|
| @@ -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; | ||
| } |
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,65 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cctype> | ||
|
|
||
| const char dif_letters = 'a' - 'A'; | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| size_t count = 1, last_ind = size - 1; | ||
| size_t start_rep_ind, end_rep_ind; | ||
|
|
||
| for (size_t i = 0; i < size; ++i) { | ||
| if (i == size - 1) { | ||
| return last_ind; | ||
| } | ||
|
|
||
| if (array[i] == array[i + 1]) { | ||
| if (count == 1) start_rep_ind = i; | ||
| count++; | ||
|
|
||
| if (array[i] == ' ') continue; | ||
| } | ||
| else if (count != 1) { | ||
| end_rep_ind = i + 1; | ||
| i = start_rep_ind; | ||
|
|
||
| size_t ind_next_simbol = i + 2; | ||
| last_ind -= count - 2; | ||
|
|
||
| if (array[i] != ' ') { | ||
| if (count >= 10) array[++i] = '0'; | ||
| else array[++i] = static_cast<char>(static_cast<size_t>('0') + count); | ||
| } | ||
| else { | ||
| --ind_next_simbol; | ||
| --last_ind; | ||
| array[i] = delimiter; | ||
| } | ||
|
|
||
| for (size_t j = end_rep_ind; j < size; ++j) { | ||
| std::swap(array[ind_next_simbol], array[j]); | ||
| ++ind_next_simbol; | ||
| } | ||
|
|
||
| size_t reduct_size = end_rep_ind - start_rep_ind; | ||
| size -= reduct_size - 2; | ||
| count = 1; | ||
| continue; | ||
| } | ||
|
|
||
| if (std::isdigit(array[i])) { | ||
| array[i] = '*'; | ||
| } | ||
| else if (std::islower(array[i])) { | ||
| array[i] -= dif_letters; | ||
| } | ||
| else if (std::ispunct(array[i])) { | ||
| array[i] = '_'; | ||
| } | ||
| else if (std::isspace(array[i])) { | ||
| array[i] = delimiter; | ||
| } | ||
| } | ||
|
|
||
| return last_ind; | ||
| } |
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,5 +1,6 @@ | ||
| #include <cstdint> | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
|
|
||
|
|
||
| enum class CheckFlags : uint8_t { | ||
|
|
@@ -14,5 +15,54 @@ enum class CheckFlags : uint8_t { | |
| }; | ||
|
|
||
| void PrintCheckFlags(CheckFlags flags) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| if (flags > CheckFlags::ALL) { | ||
| std::cout << ""; | ||
| return; | ||
| } | ||
|
|
||
| bool the_first = true; | ||
| std::string str_flags = "["; | ||
|
|
||
| size_t max_value_flag = 32; | ||
| for (size_t i = 0; i < max_value_flag; i >>= 1) { | ||
| auto b_i = static_cast<uint8_t>(flags) >> i & 1u; | ||
| if (b_i) { | ||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
| if (static_cast<uint8_t>(flags) & | ||
| static_cast<uint8_t>(CheckFlags::TIME)) { | ||
| str_flags += "TIME"; | ||
| the_first = false; | ||
| } | ||
| if (static_cast<uint8_t>(flags) & | ||
| static_cast<uint8_t>(CheckFlags::DATE)) { | ||
| the_first ? str_flags += "DATE" : str_flags += ",DATE"; | ||
| the_first = false; | ||
| } | ||
| if (static_cast<int8_t>(flags) & | ||
| static_cast<int8_t>(CheckFlags::USER) ) { | ||
| the_first ? str_flags += "USER" : str_flags += ",USER"; | ||
| the_first = false; | ||
| } | ||
| if (static_cast<int8_t>(flags) & | ||
| static_cast<int8_t>(CheckFlags::CERT)) { | ||
| the_first ? str_flags += "CERT" : str_flags += ",CERT"; | ||
| the_first = false; | ||
| } | ||
| if (static_cast<int8_t>(flags) & | ||
| static_cast<int8_t>(CheckFlags::KEYS)) { | ||
| the_first ? str_flags += "KEYS" : str_flags += ",KEYS"; | ||
| the_first = false; | ||
| } | ||
| if (static_cast<int8_t>(flags) & | ||
| static_cast<int8_t>(CheckFlags::DEST)) { | ||
| the_first ? str_flags += "DEST" : str_flags += ",DEST"; | ||
| the_first = false; | ||
| } | ||
|
Contributor
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. много дублирования кода, можно код построить более оптимально без дублирвоания |
||
|
|
||
| str_flags += "]"; | ||
| std::cout << str_flags; | ||
| } | ||
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,65 @@ | ||
| namespace { | ||
| const double m_in_inch = 0.0254; | ||
| const double m_in_foot = 0.3048; | ||
| const double m_in_cm = 0.01; | ||
| } | ||
|
|
||
|
|
||
| // m | ||
| constexpr long double operator""_m_to_m(long double m) { | ||
| return m; | ||
| } | ||
| constexpr long double operator""_m_to_in(long double m) { | ||
| return m / m_in_inch; | ||
| } | ||
| constexpr long double operator""_m_to_ft(long double m) { | ||
| return m / m_in_foot; | ||
| } | ||
| constexpr long double operator""_m_to_cm(long double m) { | ||
| return m / m_in_cm; | ||
| } | ||
|
|
||
|
|
||
| // cm | ||
| constexpr long double operator""_cm_to_cm(long double cm) { | ||
| return cm; | ||
| } | ||
| constexpr long double operator""_cm_to_in(long double cm) { | ||
| return cm / (m_in_inch / m_in_cm); | ||
| } | ||
| constexpr long double operator""_cm_to_ft(long double cm) { | ||
| return cm / (m_in_foot / m_in_cm); | ||
| } | ||
| constexpr long double operator""_cm_to_m(long double cm) { | ||
| return cm / m_in_cm; | ||
| } | ||
|
|
||
|
|
||
| // foot | ||
| constexpr long double operator""_ft_to_ft(long double ft) { | ||
| return ft; | ||
| } | ||
| constexpr long double operator""_ft_to_in(long double ft) { | ||
| return ft * (m_in_foot / m_in_inch); | ||
| } | ||
| constexpr long double operator""_ft_to_m(long double ft) { | ||
| return ft * m_in_foot; | ||
| } | ||
| constexpr long double operator""_ft_to_cm(long double ft) { | ||
| return ft * (m_in_foot / m_in_cm); | ||
| } | ||
|
|
||
|
|
||
| // inch | ||
| constexpr long double operator""_in_to_in(long double in) { | ||
| return in; | ||
| } | ||
| constexpr long double operator""_in_to_ft(long double in) { | ||
| return in * (m_in_inch / m_in_foot); | ||
| } | ||
| constexpr long double operator""_in_to_m(long double in) { | ||
| return in * m_in_inch; | ||
| } | ||
| constexpr long double operator""_in_to_cm(long double in) { | ||
| return in * (m_in_inch / m_in_cm); | ||
| } |
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,17 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
|
|
||
| #include <iostream> | ||
| #include <algorithm> | ||
|
|
||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| auto count_bits = bytes * 8; | ||
| std::string str_bset = "0b"; | ||
|
|
||
| for (size_t i = count_bits; i > 0; --i) { | ||
| auto b_i = (value >> (i - 1)) & 1u; | ||
| b_i ? str_bset += "1" : str_bset += "0"; | ||
|
|
||
| if ((i - 1) % 4 == 0 && i != count_bits && i != 1) { | ||
| str_bset += '\''; | ||
| } | ||
| } | ||
| std::cout << str_bset << "\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,68 @@ | ||
| #include <stdexcept> | ||
|
|
||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <cmath> | ||
|
|
||
| void SolveQuadratic(int a, int b, int c) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| double x_1, x_2; | ||
| bool a_is_zero = a == 0; | ||
| bool b_is_zero = b == 0; | ||
| bool c_is_zero = c == 0; | ||
|
|
||
| std::cout << std::setprecision(6); | ||
|
|
||
| if (a_is_zero && b_is_zero && c_is_zero) { | ||
| std::cout << "infinite solutions"; | ||
| return; | ||
| } else if (a_is_zero && b_is_zero && !c_is_zero) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } else if (a_is_zero && !b_is_zero && c_is_zero) { | ||
| std::cout << c; | ||
| return; | ||
| } else if (a_is_zero && !b_is_zero && !c_is_zero) { | ||
| x_1 = static_cast<double>(-c) / static_cast<double>(b); | ||
| std::cout << x_1; | ||
| return; | ||
| } else if (!a_is_zero && b_is_zero && c_is_zero) { | ||
| std::cout << "0"; | ||
| return; | ||
| } else if (!a_is_zero && b_is_zero && !c_is_zero) { | ||
| if (a * c > 0) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
| x_2 = std::sqrt(static_cast<double>(-c) / static_cast<double>(a)); | ||
| x_1 = -x_2; | ||
| std::cout << x_1 << " " << x_2; | ||
| return; | ||
| } else if (!a_is_zero && !b_is_zero && c_is_zero) { | ||
| x_1 = 0.; | ||
| x_2 = static_cast<double>(-b) / a; | ||
| if (x_1 > x_2) std::swap(x_1, x_2); | ||
| std::cout << x_1 << " " << x_2; | ||
| return; | ||
| } | ||
|
|
||
| double D_2 = b * b - 4.0 * a * c; | ||
| double eps = 1e-14; | ||
|
|
||
| if (D_2 < 0) { | ||
| std::cout << "no solutions"; | ||
| return; | ||
| } | ||
| else if (D_2 < eps) { | ||
| x_1 = static_cast<double>(-b) / (2 * a); | ||
| std::cout << x_1; | ||
| return; | ||
| } | ||
| else { | ||
| double D = std::sqrt(D_2); | ||
| x_1 = (-b + D) / (2 * a); | ||
| x_2 = (-b - D) / (2 * a); | ||
| if (x_1 > x_2) std::swap(x_1, x_2); | ||
| std::cout << x_1 << " " << x_2; | ||
| return; | ||
| } | ||
| } |
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,11 @@ | ||
| #include <cstdef> | ||
| #include <stdexcept> | ||
|
|
||
| #include <cstddef> | ||
| #include <cmath> | ||
|
|
||
| double CalculateRMS(double values[], size_t size) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| if (values == nullptr || size == 0) return static_cast<double>(0.0); | ||
| double sum = 0.0; | ||
| for (size_t i = 0; i < size; ++i) { | ||
| sum += values[i] * values[i]; | ||
| } | ||
| return std::sqrt(sum / 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,12 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| double ApplyOperations(double a, double b /* other arguments */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| double ApplyOperations(const double a, const double b, | ||
| double (*operations[])(const double, const double), size_t countOperations) | ||
| { | ||
| double res = 0.0; | ||
| for (size_t i = 0; i < countOperations; ++i){ | ||
| if (operations[i] != nullptr) res += operations[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,14 @@ | ||
| #include <stdexcept> | ||
|
|
||
| const int* FindLastElement(const int* begin, const int* end, | ||
| bool(*predicate)(int)) { | ||
|
|
||
| if (!predicate || !begin || !end || std::distance(begin, end) < 0) | ||
| return end; | ||
|
|
||
| for(const int* it = end - 1; it != begin - 1; --it) { | ||
| if (predicate(*it)) return it; | ||
| } | ||
|
|
||
| /* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| return end; | ||
| } |
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.
дублируется DATE