Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

게임 개발 메모장

36. inversion sequence 본문

문제 해결력 훈련

36. inversion sequence

Dev_Moses 2024. 1. 10. 10:57

 

▣ 입력예제 

 

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