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;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 1083번 소트 (0) | 2020.03.06 |
---|---|
[C++] 백준 9576번 책 나눠주기 (0) | 2020.02.10 |
[C++] 백준 17144번 미세먼지 안녕! (0) | 2020.01.04 |
[C++] 백준 15685번 드래곤 커브 (0) | 2019.12.30 |
[C++] 백준 1620번 나는야 포켓몬 마스터 이다솜 (1) | 2019.12.10 |