백준(C++)/정렬

[BOJ/C++]2750번_수정렬하기

코잼민 2024. 7. 7. 15:56

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

##문제 풀기 전 내가 알고 있었어야 할 개념:

 C++에서 QuickSort 헤더 라이브러리 사용 방법  

=> 자세한 내용은 https://kojammin.tistory.com/24 에 적어 놓았다.

 

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
31
32
33
#include <iostream>
#include <algorithm>//퀵 소트 사용을 위한 헤더
#define SIZE 1000//문제 조건의 N의 크기 (1000)
 
using namespace std;
 
//작은 순으로 정렬 compare
int compare(const void* a, const void* b) {
    return (*(int*)a - *(int*)b);
}
 
int main() {
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    int N,arr[SIZE];
 
    cin >> N;
 
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
 
    qsort(arr, N, sizeof(int), compare);
 
    for (int i = 0; i < N; i++) {
        cout << arr[i] << '\n';
    }
 
    return 0;
}
cs