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 |
Tags
- map
- 배열
- vector
- int
- 분할정복
- 티스토리챌린지
- N과M
- 백트래킹
- priority_queue
- BFS
- DP
- 정렬
- 다이나믹프로그래밍
- 그래프
- 깊이우선탐색
- 오블완
- 알고리즘
- 최소공배수
- stoi
- 프로그래머스
- 이분탐색
- DFS
- 우선순위큐
- C++
- Set
- Sort
- 문자열
- 에라토스테네스의 체
- 유클리드호제법
- 백준
Archives
- Today
- Total
안녕 세상아,
[백준/c++] 10814 나이순 정렬 본문
https://www.acmicpc.net/problem/10814
1. vector pair 사용해서 값 받아오기
2. stable_sort 사용해서 정렬
- 동일한 키값을 가지는 요소들의 입력 순서 유지
3. cmp 함수 만들어서 first값만 비교
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<int, string> a, pair<int, string> b) {
return a.first < b.first;
}
int main() {
vector<pair<int, string>> v;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int x;
string y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
stable_sort(v.begin(), v.end(),cmp);
for (int i = 0; i < v.size(); i++) {
cout << v[i].first << " " << v[i].second << '\n';
}
}
'백준' 카테고리의 다른 글
[백준/c++] 2776 암기왕 (0) | 2025.01.13 |
---|---|
[백준/c++] 1436 영화감독 (0) | 2025.01.08 |
[백준/c++] 분수 찾기 (0) | 2025.01.02 |
[백준/c++] 좌표 정렬하기 (1) | 2025.01.01 |
[백준/c++] 4673 셀프 넘버 (1) | 2024.12.28 |