forked from rene-d/hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp-variadics.cpp
48 lines (42 loc) · 932 Bytes
/
cpp-variadics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// https://www.hackerrank.com/challenges/cpp-variadics/problem
#include <iostream>
using namespace std;
// Enter your code for reversed_binary_value<bool...>()
template<bool...digits>
int reversed_binary_value(...)
{
//bool bits[] = { digits... };
auto i = 0, r = 0;
for (auto b : { digits... })
{
if (b) r |= 1 << i;
i++;
}
return r;
}
template <int n, bool...digits>
struct CheckValues {
static void check(int x, int y)
{
CheckValues<n-1, 0, digits...>::check(x, y);
CheckValues<n-1, 1, digits...>::check(x, y);
}
};
template <bool...digits>
struct CheckValues<0, digits...> {
static void check(int x, int y)
{
int z = reversed_binary_value<digits...>();
std::cout << (z+64*y==x);
}
};
int main()
{
int t; std::cin >> t;
for (int i=0; i!=t; ++i) {
int x, y;
cin >> x >> y;
CheckValues<6>::check(x, y);
cout << "\n";
}
}