Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c1e503

Browse files
authored
Update 2.cpp
1 parent33363aa commit1c1e503

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎21/2.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<bits/stdc++.h>
2+
3+
usingnamespacestd;
4+
5+
voidheapSort(vector<int>& arr) {
6+
priority_queue<int> h;
7+
// 모든 원소를 차례대로 힙에 삽입
8+
for (int i =0; i < arr.size(); i++) {
9+
h.push(-arr[i]);
10+
}
11+
// 힙에 삽입된 모든 원소를 차례대로 꺼내어 출력
12+
while (!h.empty()) {
13+
printf("%d\n", -h.top());
14+
h.pop();
15+
}
16+
}
17+
18+
int n;
19+
vector<int> arr;
20+
21+
intmain() {
22+
cin >> n;
23+
for (int i =0; i < n; i++) {
24+
int x;
25+
scanf("%d", &x);
26+
arr.push_back(x);
27+
}
28+
heapSort(arr);
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp