"프로그래머스 120880 특이한 정렬"의 두 판 사이의 차이

(새 문서: ==개요== {{프로그래머스|레벨=0|페이지=8}} ==C++== <syntaxhighlight lang='cpp'> #include <string> #include <vector> #include <algorithm> using namespace std; vector<int>...)
 
 
1번째 줄: 1번째 줄:
==개요==
==개요==
{{프로그래머스|레벨=0|페이지=8}}
{{프로그래머스|레벨=0|페이지=8|분류=코딩테스트 입문}}
[[분류: 프로그래머스 입문 캘린더]]
* [[프로그래머스 입문 캘린더]]


==C++==
==C++==

2023년 11월 27일 (월) 19:41 기준 최신판

1 개요[ | ]

프로그래머스 120880 특이한 정렬

2 C++[ | ]

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(vector<int> numlist, int n) {
    sort(numlist.begin(), numlist.end(), [n](int a, int b) {
        int c = abs(n-a);
        int d = abs(n-b);
        if(c == d) {
            return b < a;
        }
        return c < d;
    });
    return numlist;
}