끄적끄적 코딩
article thumbnail
728x90

정렬 문제입니다.

범위는 -1,000,000 ~ 1,000,000 이므로 200만 1개의 배열을 선언해주었습니다.
입력받는 수에서 1,000,001을 더해서 배열에 넣어주었습니다.
그리고 뒤에서 부터 for문을 돌면서 체크되어있는 수를 출력해주었습니다.

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <string>
using namespace std;

const int MAX = 2000002;
bool arr[MAX];

int main(int argc, char *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	int num;
	memset(arr, false, sizeof(arr));

	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> num;
		arr[num + 1000001] = true;
	}

	for (int i = MAX - 1; i > 0; --i) {
		if (arr[i]) {
			cout << i - 1000001 << "\n";
		}
	}

	return 0;
}

검색 태그