/
lyapdy
/
Object_oriented_programming_cpp_318
Обзор
Документация
Войти
/
lyapdy
/
Object_oriented_programming_cpp_318
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lab5/task_8.cpp
119 строк
4 KB
danillyapunov
some commit
21 авг 2025, 15:53
21 авг 2025, 15:53
a2fe910
Код
Авторство
О чём код?
#include <iostream> #include <string> #include <cctype> // ��� isspace() #include <unordered_map> #include "task_8.h" // ������� Address struct Address { std::string Country; std::string City; std::string Street; std::string House; }; // �㭪�� ���ᨭ�� ��ப� � �������� Address void Parse(std::string& line, Address* const address) { // �ࠫ� const size_t pos = 0; // ���ᨬ ��࠭� pos = line.find(','); if (pos != std::string::npos) { address->Country = line.substr(0, pos); line.erase(0, pos + 1); // ������ ����� �������� ��ப� } // ���ᨬ ��த pos = line.find(','); if (pos != std::string::npos) { address->City = line.substr(0, pos); line.erase(0, pos + 1); } // ���ᨬ 㫨�� pos = line.find(','); if (pos != std::string::npos) { address->Street = line.substr(0, pos); line.erase(0, pos + 1); } // ��⠢���� ��ப� ? �� ��� address->House = line; } // �ᯮ����⥫�� ⠡���� ᮮ⢥��⢨� ࠧ��� �ଠ⮢ ����ᥩ static const std::unordered_map<std::string, std::string> streetTypes = { {"��-�", "���"}, {"�.", "�."}, {"��.", "��."}, {"��-�", "��."}, // ��ᯥ�� {"���.", "���."}, // ���㫮� {"���", "�."}, {"�-�", "��."}, // ��좠� {"��.", "��."}, // ����� {"���.", "���."}, // ����०��� {"��.", "��."}, // �㯨� {"���", "���"} }; // ������ᠫ쭠� �㭪�� ��� ������ ������ �ࠣ���� ⥪�� ��㣨� void replaceAll(std::string& str, const std::string& from, const std::string& to) { size_t start_pos = 0; while ((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); // ᬥ饭�� ����樨 ����� } } void Trim(std::string &s) { int i = 0; while (i < static_cast<int>(s.length()) && isspace(static_cast<unsigned char>(s[i]))) ++i; s.erase(0, i); // 㤠��� ����騥 ���� i = s.length() - 1; while (i >= 0 && isspace(static_cast<unsigned char>(s[i]))) --i; s.erase(i + 1); // 㤠��� 墮�⮢� ���� } // �㭪�� �ਢ������ ��������⮢ ���� � ��������� ���� void Unify(Address* const address) { // ���砫� ��頥� �� ��譨� ����� Trim(address->Country); Trim(address->City); Trim(address->Street); Trim(address->House); // �८�ࠧ������ 㫨�� for (const auto& entry : streetTypes) { replaceAll(address->Street, entry.first, entry.second); } // �������⥫쭮 �८�ࠧ㥬 ��⠫�� ����, � �㦭� } // ��ନ�㥬 ��ᨢ�� ��ப� �ଠ� ���� std::string Format(const Address& address) { return address.Country + ", " + address.City + ", " + address.Street + ", " + address.House; } // �᭮���� �ணࠬ�� void task_8() { std::cout << "������� 8" << '\n'; std::string line; do { std::cout << "������ ����, ���ਬ��, \"������⠭, �. �����ᮢ��, �. ��������, �. 30\", ��� ������ ������ \"q\" ��� �����襭�� �����: " << '\n'; getline(std::cin, line); Address address; // ������� ��ꥪ� ��אַ � �⥪� Parse(line, &address); // ������塞 �������� Unify(&address); // �ਢ���� ���� � ��ଠ�쭮�� ���� if (!(address.Country.empty())) std::cout << Format(address) << "\n"; // �뢮��� �ଠ����� ���� } while (line != "q"); std::cout << "���ᨡ� �� ���⨥! ��������, ������ ������� \"Enter\" ��� �����襭�� �ணࠬ��." << '\n'; }