// 2024 IUSB Programming Competition // Round 2 Problem 2 // Word Scamble // Solution by Liguo Yu #include #include #include #include #include std::unordered_set Generate(const std::string& word) { std::unordered_set perm; if (word.empty()) { perm.insert(""); return perm; } char initial = word[0]; std::string rem = word.substr(1); auto words = Generate(rem); for (const auto& strNew : words) { for (size_t i = 0; i <= strNew.length(); ++i) { perm.insert(strNew.substr(0, i) + initial + strNew.substr(i)); } } return perm; } int main() { std::string word; std::cin >> word; auto words = Generate(word); std::vector sortedList(words.begin(), words.end()); std::sort(sortedList.begin(), sortedList.end()); for (const auto& str : sortedList) { std::cout << str << std::endl; } return 0; }