Skip to content

Commit

Permalink
Merge pull request #3385 from animagus12/add-the-bit-game
Browse files Browse the repository at this point in the history
Added the bit game
  • Loading branch information
ZoranPandovski authored Oct 18, 2022
2 parents 335090e + 3fbbedc commit a17c951
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions bit_manipulation/The_Bit_Game/cpp/the_bit_game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// { Driver Code Starts
#include <bits.h/stdc++.h>
#include<iostream>
using namespace std;
// } Driver Code Ends

class Solution
{
public:
int swapBitGame(long long N)
{
// Code here
int count = 0;
while (N > 0)
{
if (N % 2 == 1)
{
count++;
}
N /= 2;
}
return (count % 2 == 0) ? 2 : 1;
}
};

// { Driver Code Starts
int main()
{
int t;
cin >> t;
while (t--)
{
long long N;
cin >> N;
Solution ob;
cout << ob.swapBitGame(N) << endl;
}
return 0;
}
// } Driver Code Ends

0 comments on commit a17c951

Please sign in to comment.