Baekjoon 11651. 좌표 정렬하기 c++ [Silver V]

2024. 11. 28. 17:05·Baekjoon/Silver
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]  (2) 2024.11.21
Baekjoon 2751. 수 정렬하기 2 c++ [Silver V]  (1) 2024.11.07
Baekjoon 1018. 체스판 다시 칠하기 c++ [Silver IV]  (1) 2024.11.06
'Baekjoon/Silver' 카테고리의 다른 글
  • Baekjoon 2839.ŠEĆER c++ [Silver IV]
  • Baekjoon 1920.수 찾기 c++ [Silver V]
  • Baekjoon 1676. 팩토리얼 0의 개수 c++ [Silver V]
  • Baekjoon 2751. 수 정렬하기 2 c++ [Silver V]
Hun-bot
Hun-bot
IT를 중심으로 다양한 것
  • Hun-bot
    로봇이 만드는 눈사람
    Hun-bot
  • 전체
    오늘
    어제
    • All Article (128)
      • Programmers (6)
        • TIP (1)
        • SQL (2)
        • LV1 (1)
        • LV2 (2)
        • LV3 (0)
      • Baekjoon (31)
        • Bronze (10)
        • Silver (19)
        • Gold (2)
        • Platinum (0)
        • Diamond (0)
      • Leetcode (0)
        • Easy (0)
        • Medium (0)
        • Hard (0)
        • SQL (0)
      • 알고리즘(Algorithm) (42)
      • JavaScript (40)
      • Linux (7)
      • JSP (1)
  • 블로그 메뉴

    • 링크

    • 공지사항

    • 인기 글

    • 태그

      리눅스 #입문
      JS #JavaScript #프로그래머스 #카카오
      Programmers
      JS #javascript #객체 #Object
      Javascript
      자바스크립트
      알고리즘
      JS #JavaScript #프로그래머스 #알고리즘
      JS #클래스
      자바스크립트 #연습문제
      프로그래머스
      고득점 Kit
      LeetCode #JS #Javascript #Algorithm
      Algorithm
      JS #프로그래머스 #숫자의표현 #알고리즘
      JS #정규표현식
      프로그래머스 #자바스크립트 #JS
      SQL
      Python #알고리즘
      백준
      티스토리챌린지
      BaekJoon
      리눅스
      c++
      JavaScript #Set #Collection
      JSP #Vscode #톰켓 #Tomcat #Java #Web #jdk
      Vue #Vue.js #정리
      알고리즘 #Algorithm
      async await #js #문법 #자바스크립트 #비동기
      오블완
    • 최근 댓글

    • hELLO· Designed By정상우.v4.10.3
    Hun-bot
    Baekjoon 11651. 좌표 정렬하기 c++ [Silver V]
    상단으로

    티스토리툴바

    티스토리툴바