Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- int main() {
- string word;
- // Считываем слова по одному из ввода
- while (cin >> word) {
- // Находим следующую перестановку, если она существует
- if (next_permutation(word.begin(), word.end())) {
- cout << word << endl;
- }
- else {
- // Если следующая перестановка не существует, выводим первую перестановку
- sort(word.begin(), word.end());
- cout << word << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement