C++
x
24
1
2
3
4
5
int main(void) {
6
auto values = std::vector<int> {
7
12, 10, 10, 9, 8, 8, 8
8
};
9
10
auto sortRule = [] (int const& s1, int const& s2) -> bool
11
{
12
bool spec1 = s1 % 2 == 0 && s1 % 4 != 0;
13
bool spec2 = s2 % 2 == 0 && s2 % 4 != 0;
14
15
// using the fact that false < true
16
return spec1 < spec2 ? s1 < s2 : s2 < s1;
17
};
18
19
std::sort(values.begin(), values.end(), sortRule);
20
21
for (auto v : values) std::cout << v << ", ";
22
std::cout << '\n';
23
}
24
$ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic
Start
12, 9, 8, 8, 8, 10, 10,
0
Finish