문제 :
https://www.acmicpc.net/problem/10972
10972번: 다음 순열
첫째 줄에 입력으로 주어진 순열의 다음에 오는 순열을 출력한다. 만약, 사전순으로 마지막에 오는 순열인 경우에는 -1을 출력한다.
www.acmicpc.net
소스 :
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int num[10000] = {0};
for (int i = 0; i < n; i++)
{
cin >> num[i];
}
bool check = next_permutation(num, &num[n]);
if (check)
{
for (int i = 0; i < n; i++)
{
cout << num[i];
if (i + 1 < n)
{
cout << " ";
}
}
cout << "\n";
}
else
{
cout << -1 << endl;
}
return 0;
}
'algorithm > ACMICPC' 카테고리의 다른 글
모든 순열 - 10974 (0) | 2019.11.19 |
---|---|
이전 순열 - 10973 (0) | 2019.11.19 |
차이를 최대로 - 10819 (0) | 2019.11.19 |
1, 2, 3 더하기 - 9095 (0) | 2019.11.19 |
일곱 난쟁이 - 2309 (0) | 2019.11.19 |
댓글