Skip to content

Conversation

@SaintNikon
Copy link

No description provided.

throw std::runtime_error{"Not implemented"};
int64_t x1 = a;
int64_t x2 = b;
return x1 + x2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

две новые переменные создаватьизлишне, достаточно в return написать выражение, используя для одного из операндов static_cast

if ((value & static_cast<uint8_t>(CheckFlags::DEST)) !=0) {
std::cout<< comma << "DEST";
comma = ",";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно было избавиться от дублирования похожего кода

constexpr double CENTIMETER = 0.01;
constexpr double FOOT = 0.3048;
constexpr double INCH = 0.0254;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это хорошо, METER только лишний в данном случае

}

std::cout << "0b";
for (int i = static_cast<int>(bytes * 8 - 1); i >= 0; i--) {
Copy link
Contributor

@18thday 18thday Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

префиксный декремент должен быть

if (b == 0) {
std::cout << "no solutions";
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше было сделать две короткие ветви с return без else и ещё оного уровня вложенности


double discriminant = static_cast<double>(b) * b - 4.0 * a * c;
if (discriminant < 0) {
std::cout << "no solutions";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

аналогично, после лучше было поставить return а дальше убрать else, у последнего не было бы вложенности и не нужно было бы пролистать оставшийся код, чтоббы увидеть, что больше ничего в std::cout не добавляется общего для случаев

double CalculateRMS(double values[], size_t size) {
throw std::runtime_error{"Not implemented"};
} No newline at end of file
if (size == 0 || values == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на nullptr часто принято не сравнивать явно, а пользоваться неявным приведением указателей к bool, !values

double mean_of_squares = sum_of_squares / size;
double rms = std::sqrt(mean_of_squares);

return rms;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выше две лишние переменные, которые не используются ещё где-то, достаточно было аписать выражение сразу в return

double ApplyOperations(double a, double b /* other arguments */) {
throw std::runtime_error{"Not implemented"};
double ApplyOperations(double a, double b, double (*operations[])(double, double), size_t size ) {
double sum = 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переменную нужно создать после прохождения условий по выходу из функций, всегда стараемся уменьшить область видимости переменных перемещая их определения ближе к непосредственному использованию

/* 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)) {
if (begin == nullptr || begin == nullptr || begin > end || begin == end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

проверка с неявным приведением к bool была бы компактнее

} No newline at end of file
void PrintMemory(double value, bool reverse = false) {
uint64_t bytes;
std::memcpy(&bytes, &value, sizeof(value));
Copy link
Contributor

@18thday 18thday Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно было переписать код чтобы не дублировать, вызывая для double и int третью функцию, куда передавать указатель, размер и флаг

}

const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) {
char* result = FindLongestSubsequence(const_cast<char*>(begin), const_cast<char*>(end), count);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это UB const_cast, в данном случае снимается константность с изначально константного объекта, это UB, корректно было всю работу перенести в константную версию и её вызывать из не константной, и тогда снимать с результата константность было бы безопасно, так как мы знали бы, что вызывали константную версию из не константной

Copy link
Contributor

@18thday 18thday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaintNikon основные моменты

  • мало заданий
  • UB const_cast
  • есть дублирования,которых можно избежать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants