Advertisement
podsolnyxxx

Дискретка 2 сем. 1 лаб. G

Apr 12th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. string word;
  9.  
  10. // Считываем слова по одному из ввода
  11. while (cin >> word) {
  12. // Находим следующую перестановку, если она существует
  13. if (next_permutation(word.begin(), word.end())) {
  14. cout << word << endl;
  15. }
  16. else {
  17. // Если следующая перестановка не существует, выводим первую перестановку
  18. sort(word.begin(), word.end());
  19. cout << word << endl;
  20. }
  21. }
  22.  
  23. return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement