-
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
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,79 @@ | ||
| #include <cstddef> | ||
| #include <stdexcept> | ||
| #include <cctype> | ||
|
|
||
|
|
||
| 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){ | ||
|
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 (array[i] == symbol) ++count; | ||
| else break; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| size_t CharChanger(char array[], size_t size, char delimiter = ' ') { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| char result[256]; | ||
|
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. это излишнее потребление памяти, можно обойтись без массива, к тому же не было ограничения на 256 символов последовательности |
||
| size_t count = 0; | ||
| size_t new_ar_pos = 0; | ||
| for (size_t i=0; i<size-1;){ | ||
| count = Counter(array, size, i); | ||
|
|
||
| if (array[i] == ' '){ | ||
| result[new_ar_pos] = delimiter; | ||
| } | ||
| else if (array[i] >= +'0' && array[i] <= +'9'){ | ||
|
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. поскольку |
||
| result[new_ar_pos] = '*'; | ||
| if (count >= 10){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = '0'; | ||
| } | ||
| else if (count > 1){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = count + '0'; | ||
| } | ||
| } | ||
| else if (array[i] >= +'a' && array[i] <= +'z'){ | ||
| result[new_ar_pos] = std::toupper(array[i]); | ||
| if (count >= 10){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = '0'; | ||
| } | ||
| else if (count > 1){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = count + '0'; | ||
| } | ||
| } | ||
| else if (array[i] >= +'A' && array[i] <= +'Z'){ | ||
| result[new_ar_pos] = array[i]; | ||
| if (count >= 10){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = '0'; | ||
| } | ||
| else if (count > 1){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = count + '0'; | ||
| } | ||
| } | ||
| else{ | ||
| result[new_ar_pos] = '_'; | ||
| if (count >= 10){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = '0'; | ||
| } | ||
| else if (count > 1){ | ||
| ++new_ar_pos; | ||
| result[new_ar_pos] = count + '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. Очень много дублирования кода, стоит реорганизовать код так, чтобы не было дублирования |
||
| } | ||
| i += count; | ||
| ++new_ar_pos; | ||
| } | ||
| for (size_t i = 0; i < new_ar_pos && i < size - 1; ++i) { | ||
| array[i] = result[i]; | ||
| } | ||
| array[std::min(new_ar_pos, size - 1)] = '\0'; | ||
| return new_ar_pos; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,5 +14,28 @@ enum class CheckFlags : uint8_t { | |
| }; | ||
|
|
||
| void PrintCheckFlags(CheckFlags flags) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
|
|
||
|
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. лишняя пустая строка |
||
| uint8_t flags_int = static_cast<uint8_t>(flags); | ||
| if (flags_int > static_cast<uint8_t>(CheckFlags::ALL)) { | ||
| std::cout << ""; | ||
| return; | ||
| } | ||
|
|
||
| std::string names[6] = {"TIME", "DATE", "USER", "CERT", "KEYS" , "DEST"}; | ||
| std::string result = "["; | ||
| bool symbol_added = false; | ||
|
|
||
| uint8_t mask = 1; | ||
| for (size_t i = 0; i < 6; ++i) { | ||
| mask = (1 << i); | ||
| if (flags_int & mask) { | ||
| if (symbol_added) { | ||
| result += ","; | ||
| } | ||
| result += names[i]; | ||
| symbol_added = true; | ||
| } | ||
| } | ||
|
|
||
| std::cout << result + "]"; | ||
|
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. хорошее решение задачи |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| 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 * 0.3048; | ||
| } | ||
|
|
||
| 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 * 12.0; | ||
| } | ||
|
|
||
| constexpr double operator""_in_to_m(long double inches){ | ||
| return inches * 0.0254; | ||
| } | ||
|
|
||
| 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 / 12.0; | ||
| } | ||
|
|
||
| constexpr double operator""_m_to_ft(long double meters){ | ||
| return meters * 3.280839895; | ||
|
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. В коде не принято оставлять magic value, в данном месте лучше использовать выражения. |
||
| } | ||
|
|
||
| constexpr double operator""_m_to_in(long double meters){ | ||
| return meters * 39.37007874; | ||
| } | ||
|
|
||
| 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,21 @@ | ||
| #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. все зависит от условия и действий, но можно и с |
||
| // происходит переполнение счетчика | ||
| for (int i = total_bits - 1; i >= 0; --i) { | ||
| mask = 1LL << i; | ||
|
|
||
| if (value & mask) result += '1'; | ||
| else result += '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. как будто громоздкая конструкция, ещё и наверняка не попадет в style guide, в данном случае по условию решается прибавлять 0 или 1, поэтому тернарный оператор подойдет отлично |
||
|
|
||
| if (i % 4 == 0 && i != 0) result += '\''; | ||
| } | ||
| std::cout << result << "\n"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,64 @@ | ||
| #include <stdexcept> | ||
| #include <cmath> | ||
| #include <iomanip> | ||
| #include <iostream> | ||
|
|
||
| bool isLevelLine(int a, int b){ | ||
|
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 (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. лишняя строка |
||
| } | ||
|
|
||
| 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. очень сомнительная конструкция, если |
||
|
|
||
| } | ||
|
|
||
| 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)){ | ||
| if (c == 0) result = "infinite solutions"; | ||
| else result = "no solutions"; | ||
|
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 (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.
|
||
| 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){ | ||
|
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. нет пробелов вокруг оператора = |
||
| 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){ | ||
|
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 (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 PrintingFunc(unsigned char* byte_ptr, size_t bytes, bool shouldInverse){ | ||
|
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. Общепринято использовать present simple в названиях и глагол |
||
| 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); | ||
| PrintingFunc(byte_ptr, 4, shouldInverse); | ||
|
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. некорректно явно указывать количество байт, это платформозависимый код, sizeof для этого необходимо использовать |
||
| } | ||
|
|
||
| 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); | ||
| PrintingFunc(byte_ptr, 8, shouldInverse); | ||
| } | ||
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.
int64_t, данной возможностью языка принято пользоваться и не писать лишний код