본문 바로가기
Leaning/C++

[Hackerrank] Vector-Sort

by ksw8596 2024. 11. 4.

 

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    //Enter your code here. Read input from STDIN. Print output to STDOUT
    int n
    cin >> n;
    vector<int> v(n, 0);
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++)
    {
        cout << v[i] << " ";
    }
    return 0;
}

 

Vector의 기본

  •  지정된 형식의 요소를 선형 배열에 저장하고 모든 요소에 대한 빠른 임의 액세스를 허용
  •  시퀀스 끝에서 상수 시간 삽입 및 삭제할 수 있습니다.
  •  단, 중간요소를 변경할 경우 메모리를 다시 할당하므로 좋지않다.

'Leaning > C++' 카테고리의 다른 글

[프로그래머스] 9번/ 지폐접기  (0) 2024.11.21
[Hackerrank] Vector-Erase  (0) 2024.11.04
DFS(깊이 우선 탐색), BFS(너비 우선 탐색)  (0) 2024.10.25
C++ 자료구조(STL)  (0) 2024.10.24
[HackerRank] Hotel Prices  (0) 2024.10.17