Skip to content

Фролов Кирилл Владимирович#1

Open
MrPlesk2 wants to merge 1 commit intocppdevcourse:masterfrom
MrPlesk2:master
Open

Фролов Кирилл Владимирович#1
MrPlesk2 wants to merge 1 commit intocppdevcourse:masterfrom
MrPlesk2:master

Conversation

@MrPlesk2
Copy link
Copy Markdown

No description provided.

@czertyaka
Copy link
Copy Markdown
Collaborator

czertyaka commented Oct 22, 2025

Сейчас заметил, что допустил ошибку. В GitHub Actions проект собирается без тестов. Запушил исправление в ветку master оригинального проекта, синхронизируйте пожалуйста свой форк.

Инструкция: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

Comment thread hide-secret.cpp
std::vector<int> lps(m);

int len = 0;
lps[0] = 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Поторопились вектор использовать, мы его еще не проходили) Если ваш код запустить, то получим обращение к неинициализированной памяти.

Оператор [] не выделяет память для новых элементов. Раз уж начали использовать вектор, то советую ознакомиться:

  1. https://en.cppreference.com/w/cpp/container/vector.html
  2. https://en.cppreference.com/w/cpp/container/vector/push_back.html
  3. https://en.cppreference.com/w/cpp/container/vector/resize.html

Но вообще задание решается спокойно и без динамической памяти.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

@czertyaka czertyaka left a comment

Choose a reason for hiding this comment

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

Задание принято! PR вливать не нужно. Замечания минорные, половина из них отпала когда я узнал алгоритм KMP

Comment thread hide-secret.cpp
return;
}

int m = 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Переменным лучше давать более осмысленные имена. В продакшн коде однобуквенные названия — моветон (у математиков и научных сотрудников только так принято)

Comment thread hide-secret.cpp

int m = 0;
const char* temp = secret;
while (*temp != '\0') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Для определения длины строки можно воспользоваться std::strlen. Она примерно то же самое делает

Comment thread hide-secret.cpp
return;
}

std::vector<int> lps(m);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Тут тоже лучше другое имя придумать. Понятно, что можно разобраться в назначении объекта, прочитав код дальше, но гораздо лучше, когда все сразу понятно в момент объявления объекта.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Я понял, почему вы такие имена выбрали) У вас алгоритм Кнута-Морриса-Пратта.

Comment thread hide-secret.cpp

int m = 0;
const char* temp = secret;
while (*temp != '\0') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Вот этот цикл можно было организовать проще (если не заменять на std::strlen):

int m = 0;
for (; secret[m] != '\0'; ++m) {}

Исчезла необходимость в переменной temp и снизилась когнитивная нагрузка кода

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