알고리즘

C++ 알고리즘 - 백준 1015 수열 정렬

마루설아 2025. 2. 21. 14:22

https://www.acmicpc.net/problem/1015

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

/******** 전역변수 ********/
int B[52];
int P[52];

/******** 함    수 ********/


int main(void) {
	/******** C++ INIT ********/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	/******** 지역변수 ********/
	int input1;
	int input2;
	int num = 0;

	/******** 구    현 ********/
	cin >> input1;
	
	// B 배열에 숫자 입력
	for (int i = 0; i < input1; i++) {
		cin >> B[i];
	}

	// 배열 원소는 1000보다 작거나 같으므로 i는 1000까지,
	for (int i = 1; i < 1002; i++) {
		for (int j = 0; j < input1; j++) {
			// 입력받은 B 배열을 1부터 비교하여 P에 수열 저장
			if (B[j] == i) {
				P[j] = num;
				num++;
			}
		}
	}

	for (int i = 0; i < input1; i++) {
		cout << P[i] << " ";
	}
}