Skip to content

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 25, 2025

No description provided.

int64_t Addition(int a, int b) {
throw std::runtime_error{"Not implemented"};
}
return (int64_t)a + b;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

c-style cast не уместен, static_cast

int count_repeat = 1;

std::string tmp;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

зачем все эти пустые строки?

if (array[i] == prev_ch) {
if (array[i] != ' ') {
++count_repeat;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это достаточно короткая ветвь, поэтому добавить строку присвоения из конца и continue, неудобно листать большой блок кода ниже

++count_repeat;
}
}
else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

и else убрать поскольку он станет лишним и уйдет уровень вложенности

}
}
else {
double D = b*b - 4*a*c;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

отсутствют пробелы вокруг бинарных операторов

}
}
else {
double x = (double)(-c) / b;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

снова C-style каст

if (a == 0) {
if (b == 0) {
if (c == 0) {
std::cout << "infinite solutions";
Copy link
Contributor Author

@18thday 18thday Dec 25, 2025

Choose a reason for hiding this comment

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

В данном случае излишняя вложенность, поскольку это особые случаи корректнее будет делать короткие ветки или ветки с return

}
else if (D > 0) {
double x1 = (-b - std::sqrt(D)) / (2.0*a);
double x2 = (-b + std::sqrt(D)) / (2.0*a);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

нет пробелов вокруг бинарных операторов

throw std::runtime_error{"Not implemented"};
}
if (values == nullptr || !size)
return 0.0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

местами используется с { местами без

return end;
}

for (const int *p = end - 1; p != begin - 1; p--) {
Copy link
Contributor Author

@18thday 18thday Dec 25, 2025

Choose a reason for hiding this comment

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

декремент должен быть префиксным и указатель у типа, следуем сигнатуре функции

return sum;
}

for (size_t i = 0; i < length; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

std::memset(digits, '0', sizeof(digits));

for (size_t i = 0; i < 4; ++i) {
uint8_t byte = *(reinterpret_cast<uint8_t*>(&value) + i);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

на каждом шаге делается каст, хотя можно было вынести это выше

uint8_t byte = *(reinterpret_cast<uint8_t*>(&value) + i);

for (size_t j = 0; j < 2; ++j) {
uint8_t code = (byte & (0b1111 << (j * 4))) >> (j * 4);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

сложно к восприятию


void PrintMemory(double /* write arguments here */) {
throw std::runtime_error{"Not implemented"};
void PrintMemory(double value, bool is_big_endian = false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

for (int i = 15; i >= 0; --i) {
std::cout << digits[i];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

зачем этот миллиард пустых строк? пустые строки обычно используются для выделения логики, логику получения бит в digits и логику вывода, но не каждую строчку

throw std::runtime_error{"Not implemented"};
}
if (begin >= end) {
return nullptr;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

возвращается nullptr можно объединить условия, так как это все некорректные указатели

if (*p == prev_char) {
++prev_seq_len;
}
else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

лучше else убрать и воспользовать в условие выше continue


count = max_seq_len;

return const_cast<char*>(max_seq);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Это некорректно! функция прнимающая указатели на const должна возвращать const в данном случае это UB если пришел изначальный const, поэтому в данном случае должно быть две версии функции с const и не const и уже в неконстантной версии можно вызывать константную и снимать константность с помощью каста, это корректное было бы использование

}

data.sd = std::sqrt(data.sd / values.size());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

неэффективное решение в два прохода


bool operator<(const StudentInfo& lhs, const StudentInfo& rhs) {
return std::tie(rhs.mark, lhs.score, rhs.course, lhs.birth_date) < std::tie(lhs.mark, rhs.score, lhs.course, rhs.birth_date);
} No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

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

хорошо, когда 4 аргумента, можно и друг под другом для удоства, строка уже слишком длинная

return;
}

std::vector<int> filtered;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это излишне

}
}

vec = filtered;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

это не эффективноерешение, если у нас много значений и все подходят, вместо просто проверки мы получаем перевыделение памяти, и если будет не int, а более тяжелый тип тоже долго

@@ -0,0 +1,27 @@
#include <vector>

auto FindAll(const std::vector<int>& vec, bool (*f)(int)) {
Copy link
Contributor Author

@18thday 18thday Dec 25, 2025

Choose a reason for hiding this comment

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

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

if (f(vec[i])) {
res.push_back(i);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Два прохода, а если передана тяжелая функция предикат, не эффективно

}
}

return std::make_pair(min, max);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

примерно 3 лишних пустых строки


auto MinMax(const std::vector<int>& vec) {
if (vec.empty()) {
return std::make_pair(vec.end(),vec.end());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

нет пробела после запятой

res.push_back(vec[i + 1]);
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

два прохода не нужны

Copy link
Contributor Author

@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.

  • не уместно используется C-style каст
  • местами используется постфиксный декремент инкремент вместо префиксного
  • разный стиль кода местами
  • неуместные лишние пустые строки
  • дублирование кода
  • часто неэффективные решения
  • const_cast UB

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.

1 participant