dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getPosOfRightmostSetBit ( int n ) { return log2 ( n & - n ) ; } unsigned int toggleLastKBits ( unsigned int n , unsigned int k ) { unsigned int num = ( 1 << k ) - 1 ; return ( n ^ num ) ; } unsigned int incrementByOne ( unsigned int n ) { int k = getPosOfRightmostSetBit ( ~ n ) ; n = ( ( 1 << k ) n ) ; if ( k != 0 ) n = toggleLastKBits ( n , k ) ; return n ; } int main ( ) { unsigned int n = 15 ; cout << incrementByOne ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int xnor ( int a , int b ) { if ( a < b ) swap ( a , b ) ; if ( a == 0 && b == 0 ) return 1 ; int a_rem = 0 ; int b_rem = 0 ; int count = 0 ; int xnornum = 0 ; while ( a ) { a_rem = a & 1 ; b_rem = b & 1 ; if ( a_rem == b_rem ) xnornum |= ( 1 << count ) ; count ++ ; a = a >> 1 ; b = b >> 1 ; } return xnornum ; } int main ( ) { int a = 10 , b = 50 ; cout << xnor ( a , b ) ; return 0 ; }

Accumulator variables: count, xnornum
C++ program:
#include <iostream>
using namespace std ; int togglebit ( int n ) { if ( n == 0 ) return 1 ; int i = n ; n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return i ^ n ; } int XNOR ( int num1 , int num2 ) { if ( num1 < num2 ) swap ( num1 , num2 ) ; num1 = togglebit ( num1 ) ; return num1 ^ num2 ; } int main ( ) { int num1 = 10 , num2 = 20 ; cout << XNOR ( num1 , num2 ) ; return 0 ; }

Accumulator variables: n
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MaximumSum ( int a [ ] , int b [ ] , int n ) { int sum1 = 0 , sum2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum1 |= a [ i ] ; sum2 |= b [ i ] ; } cout << sum1 + sum2 << endl ; } int main ( ) { int A [ ] = { 1 , 2 , 4 , 3 , 2 } ; int B [ ] = { 2 , 3 , 3 , 12 , 1 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; MaximumSum ( A , B , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum1, sum2
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef unsigned long long int ull ; unsigned int posOfRightmostSetBit ( ull n ) { return log2 ( n & - n ) + 1 ; } unsigned int posOfCarryBit ( ull a , ull b ) { return posOfRightmostSetBit ( a & b ) ; } int main ( ) { ull a = 10 , b = 2 ; cout << posOfCarryBit ( a , b ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPowerOfTwo ( unsigned int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } bool differAtOneBitPos ( unsigned int a , unsigned int b ) { return isPowerOfTwo ( a ^ b ) ; } int main ( ) { unsigned int a = 13 , b = 9 ; if ( differAtOneBitPos ( a , b ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef long long int ll ; ll power2 ( ll n ) { if ( n == 0 ) return 1 ; if ( n == 1 ) return 2 ; return power2 ( n / 2 ) * power2 ( n / 2 ) ; } ll multiply ( ll x , ll n ) { return x * power2 ( n ) ; } int main ( ) { ll x = 70 , n = 2 ; cout << multiply ( x , n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isDivBy2PowerM ( unsigned int n , unsigned int m ) { if ( ( n & ( ( 1 << m ) - 1 ) ) == 0 ) return true ; return false ; } int main ( ) { unsigned int n = 8 , m = 2 ; if ( isDivBy2PowerM ( n , m ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool findWinner ( int N ) { return N & 1 ; } int main ( ) { int N = 15 ; findWinner ( N ) ? ( cout << " Player ▁ A " ; ) : ( cout << " Player ▁ B " ; ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int evenbittogglenumber ( int n ) { int res = 0 , count = 0 ; for ( int temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return n ^ res ; } int main ( ) { int n = 11 ; cout << evenbittogglenumber ( n ) ; return 0 ; }

Accumulator variables: count, res
Iterator variables: temp
C++ program:
#include <bits/stdc++.h>
using namespace std ; void divide ( int n , int m ) { cout << " Remainder ▁ = ▁ " << ( ( n ) & ( m - 1 ) ) ; cout << " Quotient = " } int main ( ) { int n = 43 , m = 8 ; divide ( n , m ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxAND ( int arr [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) res = max ( res , arr [ i ] & arr [ j ] ) ; return res ; } int main ( ) { int arr [ ] = { 4 , 8 , 6 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Maximum ▁ AND ▁ Value ▁ = ▁ " << maxAND ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int index ( int i ) { return 1 + ( i >> 31 ) - ( - i >> 31 ) ; } void check ( int n ) { string s [ ] = { " negative " , " zero " , " positive " } ; int val = index ( n ) ; cout << n << " ▁ is ▁ " << s [ val ] << endl ; } int main ( ) { check ( 30 ) ; check ( -20 ) ; check ( 0 ) ; return 0 ; }

Index/key variables: val
C++ program:
#include <iostream>
using namespace std ; void compute ( unsigned long int S , unsigned long int X ) { unsigned long int A = ( S - X ) / 2 ; int a = 0 , b = 0 ; for ( int i = 0 ; i < 8 * sizeof ( S ) ; i ++ ) { unsigned long int Xi = ( X & ( 1 << i ) ) ; unsigned long int Ai = ( A & ( 1 << i ) ) ; if ( Xi == 0 && Ai == 0 ) { } else if ( Xi == 0 && Ai > 0 ) { a = ( ( 1 << i ) a ) ; b = ( ( 1 << i ) b ) ; } else if ( Xi > 0 && Ai == 0 ) { a = ( ( 1 << i ) a ) ; } { cout << " Not ▁ Possible " ; return ; } } cout << " a ▁ = ▁ " << a << endl << " b ▁ = ▁ " << b ; } int main ( ) { unsigned long int S = 17 , X = 13 ; compute ( S , X ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool checking ( string s ) { int c = 0 ; int n = s . length ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == '0' ) c ++ ; if ( c >= 6 and s [ i ] == '1' ) return true ; } return false ; } int main ( ) { string s = "100010001" ; if ( checking ( s ) ) cout << " Possible " ; else cout << " Not ▁ possible " ; return 0 ; }

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int modifyBit ( int n , int p , int b ) { int mask = 1 << p ; return ( ( n & ~ mask ) | ( b << p ) ) ; } int main ( ) { cout << modifyBit ( 6 , 2 , 0 ) << endl ; cout << modifyBit ( 6 , 5 , 1 ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned int countSetBits ( int n ) { unsigned int count = 0 ; while ( n ) { n &= ( n - 1 ) ; count ++ ; } return count ; } unsigned int countSetBitsInGivenRange ( unsigned int n , unsigned int l , unsigned int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; return countSetBits ( n & num ) ; } int main ( ) { unsigned int n = 42 ; unsigned int l = 2 , r = 5 ; cout << countSetBitsInGivenRange ( n , l , r ) ; return 0 ; }

Accumulator variables: count, n, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool areAllBitsSet ( unsigned int n ) { if ( n == 0 ) return false ; if ( ( ( n + 1 ) & n ) == 0 ) return true ; return false ; } bool isOnesComplementOfOther ( unsigned int a , unsigned int b ) { return areAllBitsSet ( a ^ b ) ; } int main ( ) { unsigned int a = 10 , b = 5 ; if ( isOnesComplementOfOther ( a , b ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findUnique ( unsigned int a [ ] , int n , int k ) { int INT_SIZE = 8 * sizeof ( unsigned int ) ; int count [ INT_SIZE ] ; memset ( count , 0 , sizeof ( count ) ) ; for ( int i = 0 ; i < INT_SIZE ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( ( a [ j ] & ( 1 << i ) ) != 0 ) count [ i ] += 1 ; unsigned res = 0 ; for ( int i = 0 ; i < INT_SIZE ; i ++ ) res += ( count [ i ] % k ) * ( 1 << i ) ; return res ; } int main ( ) { unsigned int a [ ] = { 6 , 2 , 5 , 2 , 2 , 6 , 6 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int k = 3 ; cout << findUnique ( a , n , k ) ; return 0 ; }

Index/key variables: INT_SIZE, i, j
Accumulator variables: i, j, res, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool powerOfTwo ( unsigned int n ) { return ( ! ( n & n - 1 ) ) ; } bool onlyFirstAndLastAreSet ( unsigned int n ) { if ( n == 1 ) return true ; if ( n == 2 ) return false ; return powerOfTwo ( n - 1 ) ; } int main ( ) { unsigned int n = 9 ; if ( onlyFirstAndLastAreSet ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool allBitsAreSet ( unsigned int n ) { if ( ( ( n + 1 ) & n ) == 0 ) return true ; return false ; } bool bitsAreInAltOrder ( unsigned int n ) { unsigned int num = n ^ ( n >> 1 ) ; return allBitsAreSet ( num ) ; } int main ( ) { unsigned int n = 10 ; if ( bitsAreInAltOrder ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int setBit ( int xorValue ) { int count = 0 ; while ( xorValue ) { if ( xorValue % 2 ) count ++ ; xorValue /= 2 ; } return count ; } int minFlip ( int n , int k ) { int size = log2 ( n ) + 1 ; int max = pow ( 2 , k ) - 1 ; max = max << ( size - k ) ; int xorValue = ( n ^ max ) ; return ( setBit ( xorValue ) ) ; } int main ( ) { int n = 27 , k = 3 ; cout << " Min ▁ Flips ▁ = ▁ " << minFlip ( n , k ) ; return 0 ; }

Accumulator variables: count, stdc, xorValue
C++ program:
#include <bits/stdc++.h>
using namespace std ; string allBitsSetInTheGivenRange ( unsigned int n , unsigned int l , unsigned int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; int new_num = n & num ; if ( new_num == 0 ) return " Yes " ; return " No " ; } int main ( ) { unsigned int n = 17 ; unsigned int l = 2 , r = 4 ; cout << allBitsSetInTheGivenRange ( n , l , r ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int setAllBitsAfterMSB ( int n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return n ; } void toggle ( int & n ) { n = n ^ setAllBitsAfterMSB ( n ) ; } int main ( ) { int n = 10 ; toggle ( n ) ; cout << n ; return 0 ; }

Accumulator variables: n, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getRightMostSetBit ( unsigned int n ) { return log2 ( n & - n ) + 1 ; } int posOfRightMostSameBit ( unsigned int m , unsigned int n ) { return getRightMostSetBit ( ~ ( m ^ n ) ) ; } int main ( ) { int m = 16 , n = 7 ; cout << " Position ▁ = ▁ " << posOfRightMostSameBit ( m , n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; static int posOfRightMostSameBit ( int m , int n ) { int loopCounter = 1 ; while ( m > 0 n > 0 ) { bool a = m % 2 == 1 ; bool b = n % 2 == 1 ; if ( ! ( a ^ b ) ) { return loopCounter ; } m = m >> 1 ; n = n >> 1 ; loopCounter ++ ; } return -1 ; } int main ( ) { int m = 16 , n = 7 ; cout << " Position ▁ = ▁ " << posOfRightMostSameBit ( m , n ) ; }

Accumulator variables: loopCounter
C++ program:
#include <bits/stdc++.h>
using namespace std ; string allBitsSetInTheGivenRange ( unsigned int n , unsigned int l , unsigned int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; int new_num = n & num ; if ( num == new_num ) return " Yes " ; return " No " ; } int main ( ) { unsigned int n = 22 ; unsigned int l = 2 , r = 3 ; cout << allBitsSetInTheGivenRange ( n , l , r ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; void printNonConsecutive ( int n ) { int p = ( 1 << n ) ; for ( int i = 1 ; i < p ; i ++ ) if ( ( i & ( i << 1 ) ) == 0 ) cout << i << " ▁ " ; } int main ( ) { int n = 3 ; printNonConsecutive ( n ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
#include <bits/stdc++.h>
using namespace std ; int constructNthNumber ( int group_no , int aux_num , int op ) { int INT_SIZE = 32 ; int a [ INT_SIZE ] = { 0 } ; int num = 0 , len_f ; int i = 0 ; if ( op == 2 ) { len_f = 2 * group_no ; a [ len_f - 1 ] = a [ 0 ] = 1 ; while ( aux_num ) { a [ group_no + i ] = a [ group_no - 1 - i ] = aux_num & 1 ; aux_num = aux_num >> 1 ; i ++ ; } } else if ( op == 0 ) { len_f = 2 * group_no + 1 ; a [ len_f - 1 ] = a [ 0 ] = 1 ; a [ group_no ] = 0 ; while ( aux_num ) { a [ group_no + 1 + i ] = a [ group_no - 1 - i ] = aux_num & 1 ; aux_num = aux_num >> 1 ; i ++ ; } } else { len_f = 2 * group_no + 1 ; a [ len_f - 1 ] = a [ 0 ] = 1 ; a [ group_no ] = 1 ; while ( aux_num ) { a [ group_no + 1 + i ] = a [ group_no - 1 - i ] = aux_num & 1 ; aux_num = aux_num >> 1 ; i ++ ; } } for ( i = 0 ; i < len_f ; i ++ ) num += ( 1 << i ) * a [ i ] ; return num ; } int getNthNumber ( int n ) { int group_no = 0 , group_offset ; int count_upto_group = 0 , count_temp = 1 ; int op , aux_num ; while ( count_temp < n ) { group_no ++ ; count_upto_group = count_temp ; count_temp += 3 * ( 1 << ( group_no - 1 ) ) ; } group_offset = n - count_upto_group - 1 ; if ( ( group_offset + 1 ) <= ( 1 << ( group_no - 1 ) ) ) { op = 2 ; aux_num = group_offset ; } else { if ( ( ( group_offset + 1 ) - ( 1 << ( group_no - 1 ) ) ) % 2 ) op = 0 ; else op = 1 ; aux_num = ( ( group_offset ) - ( 1 << ( group_no - 1 ) ) ) / 2 ; } return constructNthNumber ( group_no , aux_num , op ) ; } int main ( ) { int n = 9 ; cout << getNthNumber ( n ) ; return 0 ; }

Index/key variables: INT_SIZE, group_no, i
Accumulator variables: count_temp, group_no, i, num, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void shuffle ( int N , int key ) { unsigned int NO_OF_BITS = N ; unsigned int reverse_num = 0 , temp ; for ( int i = 0 ; i < NO_OF_BITS ; i ++ ) { temp = ( key & ( 1 << i ) ) ; if ( temp ) reverse_num |= ( 1 << ( ( NO_OF_BITS - 1 ) - i ) ) ; } cout << reverse_num ; } int main ( ) { int N = 3 ; unsigned int key = 3 ; shuffle ( N , key ) ; return 0 ; }

Accumulator variables: i, reverse_num, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSetBits ( int n ) { int count = 0 ; while ( n ) { n &= ( n - 1 ) ; count ++ ; } return count ; } int findSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( countSetBits ( i ) == 2 ) sum += i ; return sum ; } int main ( ) { int n = 10 ; cout << findSum ( n ) ; return 0 ; }

Accumulator variables: count, i, n, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned int toggleLastMBits ( unsigned int n , unsigned int m ) { unsigned int num = ( 1 << m ) - 1 ; return ( n ^ num ) ; } int main ( ) { unsigned int n = 107 ; unsigned int m = 4 ; cout << toggleLastMBits ( n , m ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getPosOfRightmostSetBit ( int n ) { return log2 ( n & - n ) + 1 ; } int setRightmostUnsetBit ( int n ) { if ( n == 0 ) return 1 ; if ( ( n & ( n + 1 ) ) == 0 ) return n ; int pos = getPosOfRightmostSetBit ( ~ n ) ; return ( ( 1 << ( pos - 1 ) ) n ) ; } int main ( ) { int n = 21 ; cout << setRightmostUnsetBit ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getFirstSetBitPos ( int n ) { return log2 ( n & - n ) + 1 ; } int previousSmallerInteger ( int n ) { int pos = getFirstSetBitPos ( n ) ; return ( n & ~ ( 1 << ( pos - 1 ) ) ) ; } int main ( ) { int n = 25 ; cout << previousSmallerInteger ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void createMap ( unordered_map < string , char > * um ) { ( * um ) [ "000" ] = '0' ; ( * um ) [ "001" ] = '1' ; ( * um ) [ "010" ] = '2' ; ( * um ) [ "011" ] = '3' ; ( * um ) [ "100" ] = '4' ; ( * um ) [ "101" ] = '5' ; ( * um ) [ "110" ] = '6' ; ( * um ) [ "111" ] = '7' ; } string convertBinToOct ( string bin ) { int l = bin . size ( ) ; int t = bin . find_first_of ( ' . ' ) ; int len_left = t != -1 ? t : l ; for ( int i = 1 ; i <= ( 3 - len_left % 3 ) % 3 ; i ++ ) bin = '0' + bin ; if ( t != -1 ) { int len_right = l - len_left - 1 ; for ( int i = 1 ; i <= ( 3 - len_right % 3 ) % 3 ; i ++ ) bin = bin + '0' ; } unordered_map < string , char > bin_oct_map ; createMap ( & bin_oct_map ) ; int i = 0 ; string octal = " " ; while ( 1 ) { octal += bin_oct_map [ bin . substr ( i , 3 ) ] ; i += 3 ; if ( i == bin . size ( ) ) break ; if ( bin . at ( i ) == ' . ' ) { octal += ' . ' ; i ++ ; } } return octal ; } int main ( ) { string bin = "1111001010010100001.010110110011011" ; cout << " Octal ▁ number ▁ = ▁ " << convertBinToOct ( bin ) ; return 0 ; }

Accumulator variables: i, octal, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string areAllBitsSet ( int n ) { if ( n == 0 ) return " No " ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) return " No " ; n = n >> 1 ; } return " Yes " ; } int main ( ) { int n = 7 ; cout << areAllBitsSet ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string areAllBitsSet ( int n ) { if ( n == 0 ) return " No " ; if ( ( ( n + 1 ) & n ) == 0 ) return " Yes " ; return " No " ; } int main ( ) { int n = 7 ; cout << areAllBitsSet ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getFirstSetBitPos ( int n ) { return ( log2 ( n & - n ) + 1 ) - 1 ; } int nextGreaterWithOneMoreSetBit ( int n ) { int pos = getFirstSetBitPos ( ~ n ) ; if ( pos > -1 ) return ( 1 << pos ) | n ; return ( ( n << 1 ) + 1 ) ; } int main ( ) { int n = 10 ; cout << " Next ▁ greater ▁ integer ▁ = ▁ " << nextGreaterWithOneMoreSetBit ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long CountZeroBit ( long x ) { unsigned int count = 0 ; while ( x ) { if ( ! ( x & 1LL ) ) count ++ ; x >>= 1LL ; } return count ; } long CountXORandSumEqual ( long x ) { long count = CountZeroBit ( x ) ; return ( 1LL << count ) ; } int main ( ) { long x = 10 ; cout << CountXORandSumEqual ( x ) ; return 0 ; }

Accumulator variables: count, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int missingNumber ( int arr1 [ ] , int arr2 [ ] , int n ) { int mnum = 0 ; for ( int i = 0 ; i < n ; i ++ ) mnum = mnum ^ arr1 [ i ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) mnum = mnum ^ arr2 [ i ] ; return mnum ; } int main ( ) { int arr1 [ ] = { 4 , 8 , 1 , 3 , 7 } ; int arr2 [ ] = { 7 , 4 , 3 , 1 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << " Missing ▁ number ▁ = ▁ " << missingNumber ( arr1 , arr2 , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class BitArray { int * arr ; public : BitArray ( ) { } BitArray ( int n ) { arr = new int [ ( n >> 5 ) + 1 ] ; } bool get ( int pos ) { int index = ( pos >> 5 ) ; int bitNo = ( pos & 0x1F ) ; return ( arr [ index ] & ( 1 << bitNo ) ) != 0 ; } void set ( int pos ) { int index = ( pos >> 5 ) ; int bitNo = ( pos & 0x1F ) ; arr [ index ] |= ( 1 << bitNo ) ; } void checkDuplicates ( int arr [ ] , int n ) { BitArray ba = BitArray ( 320000 ) ; for ( int i = 0 ; i < n ; i ++ ) { int num = arr [ i ] ; if ( ba . get ( num ) ) cout << num << " ▁ " ; else ba . set ( num ) ; } } } ; int main ( ) { int arr [ ] = { 1 , 5 , 1 , 10 , 12 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; BitArray obj = BitArray ( ) ; obj . checkDuplicates ( arr , n ) ; return 0 ; }

Index/key variables: i, index
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: BitArray
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max ( int a , int b , int c ) { return max ( a , max ( b , c ) ) ; } int bitCount ( int N ) { int cnt = 0 ; while ( N ) { cnt ++ ; N >>= 1 ; } return cnt ; } bool at_position ( int num , int pos ) { bool bit = num & ( 1 << pos ) ; return bit ; } void toggle ( int & num , int pos ) { num ^= ( 1 << pos ) ; } void minChangeToReachTaregetOR ( int A , int B , int K , int T ) { int maxlen = max ( bitCount ( A ) , bitCount ( B ) , bitCount ( T ) ) ; for ( int i = maxlen - 1 ; i >= 0 ; i -- ) { bool bitA = at_position ( A , i ) ; bool bitB = at_position ( B , i ) ; bool bitT = at_position ( T , i ) ; if ( bitT ) { if ( ! bitA && ! bitB ) { toggle ( B , i ) ; K -- ; } } else { if ( bitA ) { toggle ( A , i ) ; K -- ; } if ( bitB ) { toggle ( B , i ) ; K -- ; } } } if ( K < 0 ) { cout << " Not ▁ possible STRNEWLINE " ; return ; } for ( int i = maxlen - 1 ; K > 0 && i >= 0 ; -- i ) { bool bitA = at_position ( A , i ) ; bool bitB = at_position ( B , i ) ; bool bitT = at_position ( T , i ) ; if ( bitT ) { if ( bitA && bitB ) { toggle ( A , i ) ; K -- ; } } if ( bitA && ! bitB && K >= 2 ) { toggle ( A , i ) ; toggle ( B , i ) ; K -= 2 ; } } cout << A << " ▁ " << B << endl ; } int main ( ) { int A = 175 , B = 66 , K = 5 , T = 100 ; minChangeToReachTaregetOR ( A , B , K , T ) ; return 0 ; }

Accumulator variables: K, cnt, i, num, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countValues ( int x ) { int count = 0 , n = 1 ; while ( x != 0 ) { if ( x % 2 == 0 ) count += n ; n *= 2 ; x /= 2 ; } return count ; } int main ( ) { int x = 10 ; cout << countValues ( x ) ; return 0 ; }

Accumulator variables: count, n, stdc, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void constructXOR ( int A [ ] , int n ) { int XOR = 0 ; for ( int i = 0 ; i < n ; i ++ ) XOR ^= A [ i ] ; for ( int i = 0 ; i < n ; i ++ ) A [ i ] = XOR ^ A [ i ] ; } int main ( ) { int A [ ] = { 2 , 4 , 1 , 3 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; constructXOR ( A , n ) ; for ( int i = 0 ; i < n ; i ++ ) cout << A [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: XOR, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int bitCount ( int n ) { int count = 0 ; while ( n ) { if ( n & 1 ) ++ count ; n >>= 1 ; } return count ; } long long countPairsWithKDiff ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i < n - 1 ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { int xoredNum = arr [ i ] ^ arr [ j ] ; if ( k == bitCount ( xoredNum ) ) ++ ans ; } } return ans ; } int main ( ) { int k = 2 ; int arr [ ] = { 2 , 4 , 1 , 3 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Total ▁ pairs ▁ for ▁ k ▁ = ▁ " << k << " ▁ are ▁ " << countPairsWithKDiff ( arr , n , k ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long kBitDifferencePairs ( int arr [ ] , int n , int k ) { int MAX = * max_element ( arr , arr + n ) ; long long count [ MAX + 1 ] ; memset ( count , 0 , sizeof ( count ) ) ; for ( int i = 0 ; i < n ; ++ i ) ++ count [ arr [ i ] ] ; long long ans = 0 ; if ( k == 0 ) { for ( int i = 0 ; i <= MAX ; ++ i ) ans += ( count [ i ] * ( count [ i ] - 1 ) ) / 2 ; return ans ; } for ( int i = 0 ; i <= MAX ; ++ i ) { if ( ! count [ i ] ) continue ; for ( int j = i + 1 ; j <= MAX ; ++ j ) { if ( __builtin_popcount ( i ^ j ) == k ) ans += count [ i ] * count [ j ] ; } } return ans ; } int main ( ) { int k = 2 ; int arr [ ] = { 2 , 4 , 1 , 3 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Total ▁ pairs ▁ for ▁ k ▁ = ▁ " << k << " ▁ are ▁ = ▁ " << kBitDifferencePairs ( arr , n , k ) << " STRNEWLINE " ; k = 3 ; cout << " Total ▁ pairs ▁ for ▁ k ▁ = ▁ " << k << " ▁ are ▁ = ▁ " << kBitDifferencePairs ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, stdc
Iterator variables: i, j