Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define SB(mask, k) (mask |= (1 << k))
- #define TB(mask, k) (mask ^= (1 << k))
- #define GB(mask, k) ((bool)(mask & (1 << k)))
- using namespace std;
- void SetBit(int &mask, const int &k)
- {
- mask = mask | (1 << k);
- }
- void ToggleBit(int &mask, const int &k)
- {
- mask = mask ^ (1 << k);
- }
- bool GetBit(int &mask, const int &k)
- {
- return mask & (1 << k);
- }
- void ShowMask(int &mask)
- {
- cout << "Mask: ";
- for(int i=31; i>=0; i--)
- {
- cout << GB(mask, i);
- }
- cout << endl;
- }
- int main()
- {
- int mask = 0;
- int consultas;
- cin >> consultas;
- for(int i=0; i<consultas; i++)
- {
- int pos;
- cin >> pos;
- TB(mask, pos);
- ShowMask(mask);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment