Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <windows.h>
- class String {
- private:
- std::string str;
- public:
- String(const std::string& s) : str(s) {}
- std::string operator*(const String& other) {
- std::string result;
- // Проходимся по каждому символу в текущей строке
- for (char c : str) {
- // Если символ также присутствует в другой строке и отсутствует в результате,
- // добавляем его в результат
- if (other.str.find(c) != std::string::npos && result.find(c) == std::string::npos) {
- result.push_back(c);
- }
- }
- return result;
- }
- };
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- String str1("sdqcg");
- String str2("rgfas34");
- std::string intersection = str1 * str2;
- std::cout << "Пересечение: " << intersection << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement