#include <iostream> #include <algorithm> // для функции sort #include <string> bool areanagrams(std::string str1, std::string str2) { if (str1.length() != str2.length()) { return false; } std::sort(str1.begin(), str1.end()); std::sort(str2.begin(), str2.end()); return str1 == str2; } int main() { std::string str1, str2; // Ввод двух строк std::cout << "Введите первую строку: "; std::cin >> str1; std::cout << "Введите вторую строку: "; std::cin >> str2; // Проверка на анаграммность if (areanagrams(str1, str2)) { std::cout << "Строки являются анаграммами." << std::endl; } else { std::cout << "Строки не являются анаграммами." << std::endl; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter