#include #include using namespace std; int main() { string word; vector words; // first read in the words while (cin >> word) words.push_back(word); // then sort them sort(words.begin(), words.end()); // then print out the permutatins vector::iterator p = words.begin(); vector::iterator q = words.end(); while (next_permutation(p, q)) { vector::iterator current = p; while (current != q) { cout << *current << " "; ++current; } cout << "\n"; } }