반응형
https://www.acmicpc.net/problem/10814
10814번: 나이순 정렬
온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을
www.acmicpc.net
EXPLANATION
stable_sort를 사용하면 된다. (설명)
CODE
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool compare(pair<int,string> a, pair<int,string> b){
return a.first < b.first;
}
int main(){
int N;
cin >> N;
pair<int, string> input;
vector<pair<int,string>> arr;
for(int i = 0; i < N; i++){
cin >> input.first >> input.second;
arr.push_back(input);
}
stable_sort(arr.begin(), arr.end(), compare);
for(int i = 0; i < N; i++){
cout << arr[i].first << " " << arr[i].second << "\n";
}
return 0;
}

반응형
'백준BOJ > 정렬, 투 포인터' 카테고리의 다른 글
| 백준 3273 두 수의 합 (0) | 2022.07.04 |
|---|---|
| 백준 18870 좌표 압축 (0) | 2022.06.04 |
| 백준 1181 단어 정렬 (0) | 2022.06.04 |
| 백준 11650 좌표 정렬하기, 11651 좌표 정렬하기 2 (0) | 2022.06.04 |
| 백준 1427 소트인사이드 (0) | 2022.06.04 |
댓글