게임 개발 메모장
36. inversion sequence 본문
▣ 입력예제
8
5 3 4 0 2 1 1 0
▣ 출력예제
4 8 6 2 5 1 3 7
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
int n, pos;
cin >> n;
vector<int> is(n+1), os(n+1);
for (int i = 1; i <= n; ++i)
{
cin >> is[i];
}
for (int i = n; i >= 1; --i)
{
pos = i; // 8 7 6 5 4 3 2 1
for (int j = 1; j <= is[i]; ++j)
{
os[pos] = os[pos + 1];
pos++;
}
os[pos] = i;
}
for (int i = 1; i <= n; ++i)
{
cout << os[i] << " ";
}
}
'문제 해결력 훈련' 카테고리의 다른 글
39. 재귀함수 이진수 출력 (0) | 2024.01.18 |
---|---|
38. 재귀 함수 분석 (0) | 2024.01.18 |
35. LRU (0) | 2024.01.10 |
34. 교집합 (0) | 2024.01.10 |
33. 두 배열 합치기 (0) | 2024.01.10 |