Advertisement
plarmi

workcpp_6_2

Jun 21st, 2023
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <windows.h>
  5.  
  6. class String {
  7. private:
  8.     std::string str;
  9.  
  10. public:
  11.     String(const std::string& s) : str(s) {}
  12.  
  13.     std::string operator*(const String& other) {
  14.         std::string result;
  15.  
  16.         // Проходимся по каждому символу в текущей строке
  17.         for (char c : str) {
  18.             // Если символ также присутствует в другой строке и отсутствует в результате,
  19.             // добавляем его в результат
  20.             if (other.str.find(c) != std::string::npos && result.find(c) == std::string::npos) {
  21.                 result.push_back(c);
  22.             }
  23.         }
  24.  
  25.         return result;
  26.     }
  27. };
  28.  
  29. int main() {
  30.     SetConsoleCP(1251);
  31.     SetConsoleOutputCP(1251);
  32.     String str1("sdqcg");
  33.     String str2("rgfas34");
  34.  
  35.     std::string intersection = str1 * str2;
  36.     std::cout << "Пересечение: " << intersection << std::endl;
  37.  
  38.     return 0;
  39. }
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement