https://www.acmicpc.net/problem/9081
순열 문제입니다.
다음 순열을 구해주면 됩니다.
#include <iostream>
#include <algorithm>
using namespace std;
int T;
string word;
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> T;
while (T--)
{
cin >> word;
if (!next_permutation(word.begin(), word.end()))
{
prev_permutation(word.begin(), word.end());
}
cout << word << "\n";
}
return 0;
}
next_permutation을 활용하여서 다음 순열을 확인합니다.
만약 false라면 마지막 순열이라는 의미이므로 prev_permutation를 활용해서 되돌려 놓습니다.