01. 문제
https://www.acmicpc.net/problem/10814
02. 코드
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define endl "\n";
vector<pair<int, string>> v;
bool cmp(pair<int, string> a, pair<int, string> b)
{
return a.first < b.first;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//input
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int a;
string b;
cin >> a >> b;
v.push_back({ a, b });
}
//stable_sort
stable_sort(v.begin(), v.end(), cmp);
//output
for (int i = 0; i < v.size(); ++i) {
cout << v[i].first << " " << v[i].second << endl;
}
}
03. 전략
stable_sort에 의해 동등한 원소의 상대적 위치가 그대로 유지된다.
'알고리즘 > Baekjoon Online Judge' 카테고리의 다른 글
[LCS(Longest Common Subsequence, 최장 공통 부분 수열)] (0) | 2020.03.01 |
---|---|
https://www.acmicpc.net/problem/11651 (0) | 2020.02.26 |
[DP] https://www.acmicpc.net/problem/1463 (0) | 2020.02.25 |
큰 수 더하는 고전적인 방법 (0) | 2020.02.24 |
분할 정복을 이용한 최대공약수 (0) | 2020.01.27 |