[Programmers] Lv2. ํ
์ด๋ธ ํด์ ํจ์ | C++
2023. 7. 1. 15:55ใCoding Test/Programmers
๐๋ฌธ์ ๋ณด๋ฌ๊ฐ๊ธฐ
๐จ๐ปํ์ด ๊ณผ์
๋จ์ ๊ตฌํ ๋ฌธ์ ์ ๋๋ค. ๋ณ ๊ฑฐ ์์ต๋๋ค. ์ง์ง ๋ฌธ์ ์์ ์ ์ํ ์์๋๋ก ๊ตฌํํ๊ธฐ๋ง ํ๋ฉด ๋ผ์... ์๋ ์ฝ๋ ์ฒจ๋ถํ๊ฒ ์ต๋๋ค!
โ๏ธ์์ค ์ฝ๋ ๋ฐ ๊ฒฐ๊ณผ
#include <vector>
#include <algorithm>
using namespace std;
int column;
bool Compare(const vector<int>& tuple1, const vector<int>& tuple2) {
if (tuple1[column - 1] == tuple2[column - 1])
return tuple1[0] > tuple2[0];
return tuple1[column - 1] < tuple2[column - 1];
}
int Moduler(const vector<int>& tuple, int moduler) {
int sum = 0;
for (const auto& element : tuple)
sum += element % moduler;
return sum;
}
int solution(vector<vector<int>> data, int col, int row_begin, int row_end) {
int answer = 0;
column = col;
sort(data.begin(), data.end(), Compare);
for (int i = row_begin - 1; i < row_end; i++) {
int result = Moduler(data[i], i + 1);
answer ^= result;
}
return answer;
}
728x90
๋ฐ์ํ
'Coding Test > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] Lv2. ์ฐ๋ฐ์์ด ์ ์ ๋ถ | C++ (0) | 2023.07.01 |
---|---|
[Programmers] Lv2. ๋ํ์ค ๊ฒ์ | C++ (0) | 2023.07.01 |
[Programmers] Lv2. ๋ฌธ์์ด ์์ถ | C++ (0) | 2023.06.30 |
[Programmers] Lv2. ํ๋ ฌ ํ ๋๋ฆฌ ํ์ ํ๊ธฐ | C++ (0) | 2023.06.28 |
[Programmers] Lv2. ์ฐ์๋ ๋ถ๋ถ ์์ด์ ํฉ | C++ (0) | 2023.06.27 |