CPLUSPLUC Telegram 1135
🧠 C++ Задача: "Живые итераторы"

У тебя есть вектор указателей на строки. Некоторые строки могут быть nullptr, а некоторые — валидные. Напиши функцию, которая:

1. Удаляет все nullptr из вектора.
2. Преобразует каждую строку в верхний регистр на месте.
3. Возвращает отсортированный вектор строк по длине (по убыванию).

✳️ Ограничение: нельзя копировать строки. Можно только перемещать (`std::move`).

Пример:


std::vector<std::string*> data = {
new std::string("apple"),
nullptr,
new std::string("banana"),
new std::string("kiwi"),
nullptr
};


После обработки ты должен получить std::vector<std::string> вида:


["BANANA", "APPLE", "KIWI"]


💡 Разбор
1) Удаляем nullptr с помощью std::erase_if или std::remove_if + erase.

2) Используем std::transform и std::toupper — с учётом, что строки по указателю.

3) Перемещаем строки в новый std::vector<std::string>, не копируя.

4) Сортируем с кастомным компаратором [](const std::string& a, const std::string& b) { return a.size() > b.size(); }.

Важно:

- Не забыть удалить указатели или использовать unique_ptr с std::move_if_noexcept.

- Верхний регистр через std::transform(s.begin(), s.end(), s.begin(), ::toupper).


📌 Попробуй сам — задача ловит на управлении памятью и семантике перемещения.

@cpluspluc
👍96



tgoop.com/cpluspluc/1135
Create:
Last Update:

🧠 C++ Задача: "Живые итераторы"

У тебя есть вектор указателей на строки. Некоторые строки могут быть nullptr, а некоторые — валидные. Напиши функцию, которая:

1. Удаляет все nullptr из вектора.
2. Преобразует каждую строку в верхний регистр на месте.
3. Возвращает отсортированный вектор строк по длине (по убыванию).

✳️ Ограничение: нельзя копировать строки. Можно только перемещать (`std::move`).

Пример:


std::vector<std::string*> data = {
new std::string("apple"),
nullptr,
new std::string("banana"),
new std::string("kiwi"),
nullptr
};


После обработки ты должен получить std::vector<std::string> вида:


["BANANA", "APPLE", "KIWI"]


💡 Разбор
1) Удаляем nullptr с помощью std::erase_if или std::remove_if + erase.

2) Используем std::transform и std::toupper — с учётом, что строки по указателю.

3) Перемещаем строки в новый std::vector<std::string>, не копируя.

4) Сортируем с кастомным компаратором [](const std::string& a, const std::string& b) { return a.size() > b.size(); }.

Важно:

- Не забыть удалить указатели или использовать unique_ptr с std::move_if_noexcept.

- Верхний регистр через std::transform(s.begin(), s.end(), s.begin(), ::toupper).


📌 Попробуй сам — задача ловит на управлении памятью и семантике перемещения.

@cpluspluc

BY C++ Academy


Share with your friend now:
tgoop.com/cpluspluc/1135

View MORE
Open in Telegram


Telegram News

Date: |

Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. Private channels are only accessible to subscribers and don’t appear in public searches. To join a private channel, you need to receive a link from the owner (administrator). A private channel is an excellent solution for companies and teams. You can also use this type of channel to write down personal notes, reflections, etc. By the way, you can make your private channel public at any moment. Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020. While the character limit is 255, try to fit into 200 characters. This way, users will be able to take in your text fast and efficiently. Reveal the essence of your channel and provide contact information. For example, you can add a bot name, link to your pricing plans, etc.
from us


Telegram C++ Academy
FROM American