/
lyapdy
/
Object_oriented_programming_cpp_318
Обзор
Документация
Войти
/
lyapdy
/
Object_oriented_programming_cpp_318
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lab5/task_5.cpp
39 строк
2 KB
danillyapunov
some commit
21 авг 2025, 15:53
21 авг 2025, 15:53
a2fe910
Код
Авторство
О чём код?
#include <iostream> #include <string> std::string trim(const std::string& str, // �㭪�� 㤠����� ��譨� ����� � ⠡��権 const std::string& separators = " \t") // ��।��� ��ப� � ���� �� ����⠭⭮� ��뫪�, { // � १���� 祣� ��室�� ��ப� �� �������� const auto strBegin = str.find_first_not_of(separators); // ��砫�� ᨬ��� � ��ப� if (strBegin == std::string::npos) return ""; const auto strEnd = str.find_last_not_of(separators); // ������ ᨬ��� � ��ப� const auto strRange = strEnd - strBegin + 1; return str.substr(strBegin, strRange); } std::string reduce(const std::string& str, const std::string& fill = " ", const std::string& spacing = " \t") { // trim first auto result = trim(str, spacing); // ᭠砫� ���१��� � ����� // replace sub ranges auto beginSpace = result.find_first_of(spacing); while (beginSpace != std::string::npos) { const auto endSpace = result.find_first_not_of(spacing, beginSpace); const auto range = endSpace - beginSpace; result.replace(beginSpace, range, fill); const auto newStart = beginSpace + fill.length(); beginSpace = result.find_first_of(spacing, newStart); } return result; } void task_5() { std::cout << "������� 5" << '\n'; const std::string phrase = " �ਢ��, ���\t�ਢ�� ��࠭� ��� \t ��� \t"; // std::cout << "|" << trim(foo) << "|" << '\n'; std::cout << "��室��� �।�������: " << "|" << phrase << "|" << '\n'; std::cout << "����筮� �।�������: " << "|" << reduce(phrase) << "|" << '\n'; }