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
- 로보틱스
- 자료구조
- MIT opencourse
- 집합과 맵
- lqr
- 텔레스코픽로봇
- 정렬
- 구현
- 큐
- 전국 대학생 수학 경시대회
- 실버 4
- 수학
- 백준
- C++
- 다리로봇
- 논문리뷰
- HJB방정식
- std::sort
- LeggedRobot
- 최적제어
- BOJ
- mathematics for computer science
- 문자열
- 실버 5
- 대수경
- mit
- baekjoon
- baekjoon problem solving
- 6.042j
- 로봇공학
Archives
- Today
- Total
서두르지 말고 쉬지 말자
백준 11650번 좌표 정렬하기 (C++) 본문
solved.ac 티어 : 실버5
문제 유형 : 정렬
문제 해결 소감 : array랑 sort를 사용해서 문제를 해결했고 함수 포인터에 대한 개념도 학습을 다시 했다. C++ primer책으로 좀 제대로 공부하고 싶은데 이렇게 하니까 나름 공부가 되는 것 같다.
문제 해결 전략 : std::sort를 사용해서 했기 때문에 사실상 문제 그대로 구현했다.
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
int n;
int xi = 0, yi = 0;
std::array<int, 2> temparr;
std::vector<std::array<int, 2>> v;
bool comp(const std::array<int, 2> &n1, const std::array<int, 2> &n2);
int main(void) {
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> xi >> yi;
temparr.at(0) = xi;
temparr.at(1) = yi;
v.push_back(temparr);
}
std::sort(v.begin(), v.end(), comp);
for (int i = 0; i < n; i++) {
std::cout << v[i].at(0) << " " << v[i].at(1) << '\n';
}
}
bool comp(const std::array<int, 2> &n1,
const std::array<int, 2>
&n2) { // true 반환하면 첫번째 매개변수가 두번째 매개변수보다 앞에 오게 정렬됨
if (n1.at(0) == n2.at(0)) {
return n1.at(1) < n2.at(1);
} else
return n1.at(0) < n2.at(0);
}반응형
'코딩 공부 > Baekjoon Problem Solving' 카테고리의 다른 글
| 백준 14626번 ISBN (C++) (3) | 2025.07.24 |
|---|---|
| 백준 2164번 카드 2(C++) (0) | 2025.07.16 |
| 백준 1978번 소수 찾기 (C++) (1) | 2025.07.14 |
| 백준 11866번 요세푸스 문제 0 (C++) (0) | 2025.07.07 |
| 백준 15829번 Hashing (C++) (0) | 2025.07.07 |
