-
Notifications
You must be signed in to change notification settings - Fork 33
Мирошниченко Евгений #22
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?
Changes from all commits
06d76ae
613b706
2a4d55b
ae23b13
ac78ed1
6d5ca5a
973e2c1
70b559a
6abdaed
f232d92
6e33054
5040363
c2ecb84
5ccfcfd
d16d634
b5846d2
3140432
491b548
76b88a1
cec01a6
54e4f93
5a5aa8e
281a806
f13237b
8de7695
6056097
2daeaf6
31e8046
58c3ad7
874bb03
d8dc8a0
f273f6e
38792e3
8ca841e
8f13fad
bb3be57
7cc1249
ded273c
44576c4
c2a260e
b170ddf
8c9c865
72dc419
4d24f6e
12bf2b7
c8c5587
70d105d
869fe5b
c268186
fdd5565
4132904
9f310f4
7523dc1
12d57d3
cd94211
0ad4174
317890c
b59ffb4
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,7 @@ | ||
| # Build directories | ||
| build/ | ||
| */build/ | ||
| */build*/ | ||
|
|
||
| # IDE | ||
| .vscode/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,54 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cctype> | ||
|
|
||
| void ProcessOneSymbol(char* array, size_t& pos, char symbol, size_t count){ | ||
| array[pos] = symbol; | ||
| if (count >= 10){ | ||
| ++pos; | ||
| array[pos] = '0'; | ||
| } | ||
| else if (count > 1){ | ||
| ++pos; | ||
| array[pos] = count + '0'; | ||
| } | ||
| } | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| size_t Counter(char array[], size_t size, size_t startIdx){ | ||
| char symbol = array[startIdx]; | ||
| size_t count = 1; | ||
| for (size_t i = startIdx + 1; i < size - 1; ++i) { | ||
| if (array[i] == symbol) ++count; | ||
| else break; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| size_t count = 0; | ||
| size_t new_ar_pos = 0; | ||
| for (size_t i=0; i<size-1;){ | ||
| count = Counter(array, size, i); | ||
|
|
||
| if (std::isblank(array[i])){ | ||
| array[new_ar_pos] = delimiter; | ||
| } | ||
| else if (std::isdigit(array[i])){ | ||
| ProcessOneSymbol(array, new_ar_pos, '*', count); | ||
| } | ||
| else if (std::islower(array[i])){ | ||
| ProcessOneSymbol(array, new_ar_pos, std::toupper(array[i]), count); | ||
| } | ||
| else if (std::isupper(array[i])){ | ||
| ProcessOneSymbol(array, new_ar_pos, array[i], count); | ||
| } | ||
| else{ | ||
| ProcessOneSymbol(array, new_ar_pos, '_', count); | ||
| } | ||
| i += count; | ||
| ++new_ar_pos; | ||
| } | ||
|
|
||
| array[std::min(new_ar_pos, size - 1)] = '\0'; | ||
| return new_ar_pos; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| namespace{ | ||
| constexpr double FT_IN_M = 3.280839895; | ||
| constexpr double IN_IN_FT = 12.0; | ||
| constexpr double IN_IN_M = IN_IN_FT * FT_IN_M; | ||
| } | ||
|
|
||
| constexpr double operator""_m_to_cm(long double meters){ | ||
| return meters * 100; | ||
| } | ||
|
|
||
| constexpr double operator""_cm_to_m(long double centimeter){ | ||
| return centimeter / 100.0; | ||
| } | ||
|
|
||
| constexpr double operator""_ft_to_m(long double feets){ | ||
| return feets / FT_IN_M; | ||
| } | ||
|
|
||
| constexpr double operator""_ft_to_cm(long double feets){ | ||
| return operator""_m_to_cm(operator""_ft_to_m(feets)); | ||
| } | ||
|
|
||
| constexpr double operator""_ft_to_in(long double feets){ | ||
| return feets * IN_IN_FT; | ||
| } | ||
|
|
||
| constexpr double operator""_in_to_m(long double inches){ | ||
| return inches / IN_IN_M; | ||
| } | ||
|
|
||
| constexpr double operator""_in_to_cm(long double inches){ | ||
| return operator""_m_to_cm(operator""_in_to_m(inches)); | ||
| } | ||
|
|
||
| constexpr double operator""_in_to_ft(long double inches){ | ||
| return inches / IN_IN_FT; | ||
| } | ||
|
|
||
| constexpr double operator""_m_to_ft(long double meters){ | ||
| return meters * FT_IN_M; | ||
| } | ||
|
|
||
| constexpr double operator""_m_to_in(long double meters){ | ||
| return meters * IN_IN_M; | ||
| } | ||
|
|
||
| constexpr double operator""_cm_to_ft(long double centimeters){ | ||
| return operator""_cm_to_m(operator""_m_to_ft(centimeters)); | ||
| } | ||
|
|
||
| constexpr double operator""_cm_to_in(long double centimeters){ | ||
| return operator""_cm_to_m(operator""_m_to_in(centimeters)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,20 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
|
|
||
|
|
||
| void PrintBits(long long value, size_t bytes) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| std::string result = "0b"; | ||
| size_t total_bits = bytes * 8; | ||
| long long mask = 0LL; | ||
| // Тут надо int, иначе условие бесконечное, потому что будет | ||
|
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. все зависит от условия и действий, но можно и с 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 (int i = total_bits - 1; i >= 0; --i) { | ||
| mask = 1LL << i; | ||
|
|
||
| result += (value & mask) ? '1' : '0'; | ||
|
|
||
| if (i % 4 == 0 && i != 0) result += '\''; | ||
| } | ||
| std::cout << result << "\n"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,61 @@ | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
|
|
||
| bool isLevelLine(int a, int b) { | ||
| return a == 0 && b == 0; | ||
| } | ||
|
|
||
| bool isLinear(int a, int b){ | ||
| if (a == 0 && b != 0) return true; | ||
| else return false; | ||
|
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. очень сомнительная конструкция, если 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 isQuadratic(int a){ | ||
| if (a != 0) return true; | ||
| else return false; | ||
|
|
||
| } | ||
|
|
||
| std::string AddRootToStr(double x){ | ||
| std::ostringstream oss; | ||
| oss << std::setprecision(6); | ||
| if (std::abs(x - std::round(x)) < 1e-10) { | ||
| oss << static_cast<int>(std::round(x)); | ||
| } else { | ||
| oss << x; | ||
| } | ||
| return oss.str(); | ||
| } | ||
|
|
||
| void SolveQuadratic(int a, int b, int c) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| std::string result = ""; | ||
| if (isLevelLine(a, b)){ | ||
| result = (c == 0) ? "infinite solutions" : "no solutions"; | ||
| } | ||
| else if (isLinear(a, b)){ | ||
| double x = -static_cast<double>(c) / b; | ||
| result = AddRootToStr(x); | ||
| } | ||
| else if (isQuadratic(a)){ | ||
| double discr = b * b - 4 * a * c; | ||
| if (discr < 0) { | ||
| result = "no solutions"; | ||
| } | ||
| else if (std::abs(discr) < 1e-10) { | ||
| double x = -b / (2.0 * a); | ||
| result = AddRootToStr(x); | ||
| } | ||
| else { | ||
| double x1 = (-b + sqrt(discr)) / (2.0 * a); | ||
|
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.
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. Взято из cmath |
||
| double x2 = (-b - sqrt(discr)) / (2.0 * a); | ||
|
|
||
| if (x1 > x2) std::swap(x1, x2); | ||
| result = AddRootToStr(x1) + " " + AddRootToStr(x2); | ||
| } | ||
| } | ||
|
|
||
| std::cout << result; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| #include <cstdef> | ||
| #include <stdexcept> | ||
| #include <cstddef> | ||
| #include <cmath> | ||
|
|
||
|
|
||
| double CalculateRMS(double values[], size_t size) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| double res = 0.0; | ||
| if (values == nullptr || size == 0) return res; | ||
| for (size_t i = 0; i < size; ++i){ | ||
| res += values[i] * values[i]; | ||
| } | ||
| return std::sqrt(res / size); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| 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 func_count) { | ||
| double result = 0.0; | ||
| const double& a_ref = a; | ||
| const double& b_ref = b; | ||
| for (size_t i = 0; i < func_count; ++i){ | ||
| if (functions[i]){ | ||
| result += functions[i](a_ref, b_ref); | ||
| } | ||
| } | ||
| return result; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,19 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| /* return_type */ FindLastElement(/* ptr_type */ begin, /* ptr_type */ end, /* func_type */ predicate) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(int)) { | ||
| const int* result = end; | ||
| if ((begin == nullptr) || (end==nullptr) || (predicate == nullptr) || (begin > end)) { | ||
| result = end; | ||
| return result; | ||
| } | ||
|
|
||
| for (; begin != end; ++begin){ | ||
| const int elem = *begin; | ||
| if (predicate(elem)){ | ||
| result = begin; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,28 @@ | ||
| #include <stdexcept> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
| #include <sstream> | ||
|
|
||
| void Print(unsigned char* byte_ptr, size_t bytes, bool shouldInverse){ | ||
| std::ostringstream oss; | ||
| oss << "0x"; | ||
|
|
||
| for (size_t i = 0; i < bytes; ++i) { | ||
| size_t index = shouldInverse ? (bytes - 1 - i) : i; | ||
| oss << std::hex << std::uppercase << std::setw(2) << std::setfill('0') | ||
| << static_cast<int>(byte_ptr[index]); | ||
| } | ||
|
|
||
| oss << "\n"; | ||
| std::cout << oss.str(); | ||
| } | ||
|
|
||
| void PrintMemory(int /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void PrintMemory(int number, bool shouldInverse=false) { | ||
| unsigned char* byte_ptr = reinterpret_cast<unsigned char*>(&number); | ||
| Print(byte_ptr, sizeof(int), shouldInverse); | ||
| } | ||
|
|
||
| void PrintMemory(double /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void PrintMemory(double number, bool shouldInverse=false) { | ||
| unsigned char* byte_ptr = reinterpret_cast<unsigned char*>(&number); | ||
| Print(byte_ptr, sizeof(double), shouldInverse); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,37 @@ | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| /* return_type */ FindLongestSubsequence(/* ptr_type */ begin, /* ptr_type */ end, /* type */ count) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) { | ||
| const char* start_of_longest_seq = nullptr; | ||
| count = 0; | ||
| size_t this_seq_count = 0; | ||
|
|
||
| if ((begin == nullptr) || (end==nullptr) || (begin > end)) { | ||
| return start_of_longest_seq; | ||
| } | ||
|
|
||
| const char* next_el = nullptr; | ||
| while(begin != end){ | ||
| this_seq_count = 1; | ||
| if (begin < end - 1){ | ||
| next_el = begin + 1; | ||
| for (; next_el != end; ++next_el){ | ||
| if (*next_el != *begin) break; | ||
| ++this_seq_count; | ||
| } | ||
| } | ||
|
|
||
| if (this_seq_count > count){ | ||
| count = this_seq_count; | ||
| start_of_longest_seq = begin; | ||
| } | ||
| begin += this_seq_count; | ||
| } | ||
|
|
||
| return start_of_longest_seq; | ||
| } | ||
|
|
||
| char* FindLongestSubsequence(char* begin, char* end, size_t& count){ | ||
| const char* const_result = FindLongestSubsequence(const_cast<const char*>(begin), const_cast<const char*>(end), count); | ||
| return const_cast<char*>(const_result); | ||
| } |
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.
хорошее решение задачи