-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFlippingBits.cpp
More file actions
41 lines (33 loc) · 759 Bytes
/
FlippingBits.cpp
File metadata and controls
41 lines (33 loc) · 759 Bytes
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
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
// Complete the flippingBits function below.
long long BitFlip(long long n)
{
long long a[32];
for(int j=31;j>=0;j--){
a[j] = 1 - (n%2);
n/=2;
}
long long sum = 0;
for(int j=0;j<32;j++){
sum = sum + a[31-j]*pow(2,j);
}
return sum;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
long long q;
cin >> q;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int q_itr = 0; q_itr < q; q_itr++) {
long long n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
long result = BitFlip(n);
fout << result << "\n";
}
fout.close();
return 0;
}