algorithm/문제 풀이

백준 2751번 (수 정렬하기 2) C++

ssoheeh 2021. 1. 13. 23:07

문제 : 수 정렬하기 2

시간 제한 : 2 sec

메모리 제한 : 256 MB

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
 
int main() {
    int n,a;
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> v;
    REP(i, 0, n) {
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    REP(i, 0, n) {
        cout << v[i] << "\n";
    }
    v.clear();
    return 0;
}
cs

자바로 했더니 죽도록 안돌아가길래 결국 C++....

확실히 성능이 빠른 것 같긴 하다

C++ sort함수는 주소값을 줘야 하는듯