백준 10814: 나이순 정렬
2023. 1. 30. 23:11ㆍ개인공부/코딩테스트
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct MemberInfo
{
int mEnterNumber;
int mAge;
string mName;
bool operator > (const MemberInfo& _otherinfo) const
{
if (mAge > _otherinfo.mAge)
return true;
else if (mAge == _otherinfo.mAge)
{
if (mEnterNumber > _otherinfo.mEnterNumber)
{
return true;
}
else
return false;
}
else
return false;
}
};
int main(void)
{
int MemberNumber = 0;
cin >> MemberNumber;
priority_queue<MemberInfo, vector<MemberInfo>, greater<MemberInfo>> pq;
for (int i = 0; i < MemberNumber; ++i)
{
int Age = 0;
string Name{};
cin >> Age >> Name;
MemberInfo mInfo = {};
mInfo.mAge = Age;
mInfo.mName = Name;
mInfo.mEnterNumber = i;
pq.push(mInfo);
}
while (!pq.empty())
{
cout << pq.top().mAge << " " << pq.top().mName << '\n';
pq.pop();
}
return 0;
}
|
cs |
'개인공부 > 코딩테스트' 카테고리의 다른 글
백준 2798: 블랙잭 (0) | 2023.01.31 |
---|---|
백준 2108: 통계학 (0) | 2023.01.31 |
백준 1181: 단어 정렬 (0) | 2023.01.30 |
백준 2738번: 행렬 덧셈 (0) | 2023.01.30 |
백준 9020번: 골드바흐의 추측 (0) | 2023.01.30 |