-
Notifications
You must be signed in to change notification settings - Fork 372
Рассказов Алексей 4092, String #1618
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: master
Are you sure you want to change the base?
Conversation
Reckl4ma
commented
Dec 17, 2025
- Разработать интерфейс модуля для работы со строками. Основные операции: создание, конкатенация, копирование, поиск подстроки, сравнение двух строк, изменение размера, получение указателя на массив символов
- Разработать класс "срез строки", имеющий такой же интерфейс, как строка, но не хранящий собственных данных, а только ссылку на фрагмент существующей строки.
- Реализовать описанные функции
- Реализовать поиск с помощью алгоритма Кнута-Морриса-Пратта
| size_ = a.size_; | ||
| capacity_ = a.capacity_; | ||
|
|
||
| data_ = new char[capacity_]; |
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.
По идее, нужно выделять память только под size.
| String no; | ||
| set_text(no, "ZZ"); | ||
| if (text.find(no) != String::npos) { std::cout << "Fail: find not found\n"; return 1; } | ||
| } |
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.
Ещё тест производительности поиска нужен.
| static constexpr size_t npos = static_cast<size_t>(-1); | ||
| String(); | ||
|
|
||
| String(const String& a); |
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.
Нужны конструкторы из const char * и substring.
| char operator[](std::size_t index) const; | ||
|
|
||
| void print() const; | ||
|
|
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.
Нужна конвертация в String, ещё operator==, operator<, чтобы можно было складывать в контейнер и сортировать.
LibraryCPPClass/Tests/MyString.cpp
Outdated
| total_kmp_ms += std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count(); | ||
|
|
||
| t1 = std::chrono::high_resolution_clock::now(); | ||
| ans_nv = find_naive(text, pat); |
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.
Ну раз уж появилось сравнение, то неплохо бы сделать график.
А я говорил про тест, который нужно сделать только для своего поиска.
Что какой-то большой случай работает быстрее, чем O(NM). Это должно быть видно по времени, что получается секунда, а не 10 минут.
LibraryCPPClass/substring.cpp
Outdated
| result[i] = (*this)[i]; | ||
| } | ||
|
|
||
| return 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.
Конструктор же есть.