-
[ 2751 ] 수 정렬하기 2알고리즘/BOJ 2021. 8. 12. 18:17
< 정렬 > - < 실버 5 >
[ 2751 ]
수 정렬하기 2
N개의 수가 주어졌을 때, 이를 오름차순으로 정렬하는 프로그램을 작성하시오.
:: 입력
첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.
:: 출력
첫째 줄부터 N개의 줄에 오름차순으로 정렬한 결과를 한 줄에 하나씩 출력한다.
정답 코드
#include <iostream> #include <string> #include <queue> #include <algorithm> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> nums; for (int i = 0; i < n; i++) { int k; cin >> k; nums.push_back(k); } sort(nums.begin(), nums.end()); for (int i = 0; i < n; i++) { printf("%d\n", nums[i]); } return 0; }
'알고리즘 > BOJ' 카테고리의 다른 글
[ 2108 ] 통계학 (0) 2021.08.12 [ 10989 ] 수 정렬하기 3 (0) 2021.08.12 [ 6996 ] 애너그램 - array, vector (0) 2021.07.27 [ 5597 ] 과제 안 내신 분 ..? - array, vector (0) 2021.07.27 [ 2953 ] 나는 요리사다 - array, vector (0) 2021.07.27