728x90
반응형
sort부분에 Lambda함수를 사용
sort(1, 2, 3)
3번에서 []로 시작하는 부분이 Lambda를 사용한 부분이다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
vector<pair<int, int>> coordinate;
cin >> N;
for (int i = 0; i < N; i++)
{
int x, y;
cin >> x >> y;
coordinate.push_back({x, y});
}
sort(coordinate.begin(), coordinate.end(), [](const pair<int, int> &a, const pair<int, int> &b)
{
if (a.second == b.second)
return a.first < b.first;
return a.second < b.second; });
for (int i = 0; i < N; i++)
{
cout << coordinate[i].first << " " << coordinate[i].second << '\n';
}
return 0;
}
728x90
반응형
'Baekjoon > Silver' 카테고리의 다른 글
Baekjoon 2839.ŠEĆER c++ [Silver IV] (1) | 2024.12.09 |
---|---|
Baekjoon 1920.수 찾기 c++ [Silver V] (0) | 2024.12.09 |
Baekjoon 1676. 팩토리얼 0의 개수 c++ [Silver V] (0) | 2024.11.21 |
Baekjoon 2751. 수 정렬하기 2 c++ [Silver V] (0) | 2024.11.07 |
Baekjoon 1018. 체스판 다시 칠하기 c++ [Silver IV] (0) | 2024.11.06 |