Algorithm/Problem Solving
2020. 5. 22. 22:47
(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)
문제 링크
- https://www.acmicpc.net/problem/10814
사용 알고리즘
- 정렬
풀이
- STL의 stable_sort 이용
소스 코드
- https://github.com/moomini/algorithm/blob/master/boj/10814.cpp
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; bool cmp(const pair<int, string> &u, const pair<int, string> &v) { return u.first < v.first; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector<pair<int, string>> v(n); for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second; stable_sort(v.begin(), v.end(), cmp); for (int i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << "\n"; return 0; } | cs |
'Algorithm > Problem Solving' 카테고리의 다른 글
[BOJ/10989] 수 정렬하기 3 (0) | 2020.05.26 |
---|---|
[BOJ/10825] 국영수 (0) | 2020.05.24 |
[BOJ/11651] 좌표 정렬하기 2 (0) | 2020.05.21 |
[BOJ/11650] 좌표 정렬하기 (0) | 2020.05.19 |
[BOJ/2751] 수 정렬하기 2 (0) | 2020.05.18 |