Make Unreal REAL.
article thumbnail
Level 2. 테이블 해시 함수

 

 

사용자 정의 비교로 정렬할 수 있는지 묻는 문제였다.

 

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int solution(vector<vector<int>> data, int col, int row_begin, int row_end)
{
    int answer = 0;

    --col;
    auto pred = [col](auto& t1, auto& t2) { return (t1[col] == t2[col]) ? (t1[0] > t2[0]) : (t1[col] < t2[col]); };

    stable_sort(data.begin(), data.end(), pred);

    auto S = [&data](int i) { return accumulate(data[i - 1].begin(), data[i - 1].end(), 0, [i](int sum, int num) { return sum + (num % i); }); };

    for (int i = row_begin; i <= row_end; ++i)
        answer ^= S(i);

    return answer;
}

'자료구조 & 알고리즘 > 프로그래머스' 카테고리의 다른 글

Level 3. 야근 지수  (0) 2023.07.21
Level 2. 수식 최대화  (0) 2023.07.20
Level 3. 등굣길  (0) 2023.07.18
Level 3. 최고의 집합  (0) 2023.07.17
Level 3. 네트워크  (0) 2023.07.16
profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그