#include <algorithm> #include <iostream> #include <string> using namespace std;
void swap(string::iterator A, string::iterator B) { char tmp; tmp= *A; *A= *B; *B= tmp; }
int main(int argc, char const *argv[]) { string ss; string::iterator Pj, Pk; cin >> ss; while (1) { for (Pj= ss.end() - 2; Pj != ss.begin(); Pj--) { if (*Pj < *(Pj + 1)) { break; } } if (*Pj >= *(Pj + 1)) { return 0; } else { for (Pk= ss.end() - 1; Pk > Pj; Pk--) { if (*Pk > *Pj) { break; } } swap(Pj, Pk); reverse(Pj + 1, ss.end()); cout << ss << endl; } } return 0; }
|