Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- C++
- baekjoon problem solving
- lqr
- 대수경
- 텔레스코픽로봇
- 문자열
- std::sort
- 최적제어
- 정렬
- 수학
- 집합과 맵
- 자료구조
- mathematics for computer science
- 백준
- 로봇공학
- baekjoon
- HJB방정식
- 큐
- mit
- MIT opencourse
- 실버 5
- 실버 4
- 6.042j
- LeggedRobot
- 로보틱스
- 다리로봇
- BOJ
- 구현
- 전국 대학생 수학 경시대회
- 논문리뷰
Archives
- Today
- Total
서두르지 말고 쉬지 말자
백준 10814번 나이순 정렬 (C++) 본문
solved.ac 티어 : 실버 5
문제 유형 : 정렬, 집합과 맵
문제 해결 소감 : 라이브러리가 잘 되어 있어서 상대적으로 적은 노력으로 만들었는데 C로 짠다면 이라는 아찔한 생각이 든다. C로도 짤수 있을 정도로 공부해야 겠다.
문제 해결 전략 : std::pair과 std::stable_sort를 사용해서 만들었다.
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
int n;
int age;
std::string name;
std::vector<std::pair<int, std::string>> pv;
bool comparePeople(const std::pair<int, std::string>& a,
const std::pair<int, std::string>& b);
int main(void) {
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> age >> name;
pv.push_back({age, name});
}
std::stable_sort(pv.begin(), pv.end(), comparePeople);
for (const std::pair<int, std::string>& i : pv) {
std::cout << i.first << " " << i.second << '\n';
}
}
bool comparePeople(const std::pair<int, std::string>& a,
const std::pair<int, std::string>& b) {
return a.first < b.first;
}
반응형
'코딩 공부 > Baekjoon Problem Solving' 카테고리의 다른 글
| 백준 1764 듣보잡 (C++) (0) | 2025.08.04 |
|---|---|
| 백준 7568번 덩치 (C++) (2) | 2025.08.04 |
| 백준 14626번 ISBN (C++) (3) | 2025.07.24 |
| 백준 2164번 카드 2(C++) (0) | 2025.07.16 |
| 백준 11650번 좌표 정렬하기 (C++) (2) | 2025.07.14 |
