dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int ALPHABET_SIZE = 26 ; struct trieNode { trieNode * t [ ALPHABET_SIZE ] ; int isEnd ; } ; trieNode * getNode ( ) { trieNode * temp = new ( trieNode ) ; for ( int i = 0 ; i < ALPHABET_SIZE ; i ++ ) temp -> t [ i ] = NULL ; temp -> isEnd = 0 ; return temp ; } void insert ( trieNode * root , string key ) { trieNode * trail ; trail = root ; for ( int i = 0 ; i < key . length ( ) ; i ++ ) { if ( trail -> t [ key [ i ] - ' a ' ] == NULL ) { trieNode * temp ; temp = getNode ( ) ; trail -> t [ key [ i ] - ' a ' ] = temp ; } trail = trail -> t [ key [ i ] - ' a ' ] ; } ( trail -> isEnd ) ++ ; } bool search_mod ( trieNode * root , string word ) { trieNode * trail ; trail = root ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { if ( trail -> t [ word [ i ] - ' a ' ] == NULL ) return false ; trail = trail -> t [ word [ i ] - ' a ' ] ; } if ( ( trail -> isEnd ) > 0 && trail != NULL ) { ( trail -> isEnd ) -- ; return true ; } else return false ; } void checkPossibility ( string sentence [ ] , int m , trieNode * root ) { int flag = 1 ; for ( int i = 0 ; i < m ; i ++ ) { if ( search_mod ( root , sentence [ i ] ) == false ) { cout << " NO " ; return ; } } cout << " YES " ; } void insertToTrie ( string dictionary [ ] , int n , trieNode * root ) { for ( int i = 0 ; i < n ; i ++ ) insert ( root , dictionary [ i ] ) ; } int main ( ) { trieNode * root ; root = getNode ( ) ; string dictionary [ ] = { " find " , " a " , " geeks " , " all " , " for " , " on " , " geeks " , " answers " , " inter " } ; int N = sizeof ( dictionary ) / sizeof ( dictionary [ 0 ] ) ; insertToTrie ( dictionary , N , root ) ; string sentence [ ] = { " find " , " all " , " answers " , " on " , " geeks " , " for " , " geeks " } ; int M = sizeof ( sentence ) / sizeof ( sentence [ 0 ] ) ; checkPossibility ( sentence , M , root ) ; return 0 ; }

Index/key variables: ALPHABET_SIZE, i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: trieNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isGreaterThanEqualTo ( string s1 , string s2 ) { if ( s1 . size ( ) > s2 . size ( ) ) return true ; return ( s1 == s2 ) ; } string multiply ( string s1 , string s2 ) { int n = s1 . size ( ) ; int m = s2 . size ( ) ; vector < int > result ( n + m , 0 ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) for ( int j = m - 1 ; j >= 0 ; j -- ) result [ i + j + 1 ] += ( s1 [ i ] - '0' ) * ( s2 [ j ] - '0' ) ; int size = result . size ( ) ; for ( int i = size - 1 ; i > 0 ; i -- ) { if ( result [ i ] >= 10 ) { result [ i - 1 ] += result [ i ] / 10 ; result [ i ] = result [ i ] % 10 ; } } int i = 0 ; while ( i < size && result [ i ] == 0 ) i ++ ; if ( i == size ) return "0" ; string temp ; while ( i < size ) { temp += ( result [ i ] + '0' ) ; i ++ ; } return temp ; } string removeLeadingZeores ( string s ) { int n = s . size ( ) ; int i = 0 ; while ( i < n && s [ i ] == '0' ) i ++ ; if ( i == n ) return "0" ; string temp ; while ( i < n ) temp += s [ i ++ ] ; return temp ; } bool isPower ( string s1 , string s2 ) { s1 = removeLeadingZeores ( s1 ) ; s2 = removeLeadingZeores ( s2 ) ; if ( s1 == "0" s2 == "0" ) return false ; if ( s1 == "1" && s2 == "1" ) return true ; if ( s1 == "1" s2 == "1" ) return true ; if ( s1 . size ( ) > s2 . size ( ) ) return isPower ( s2 , s1 ) ; string temp = s1 ; while ( ! isGreaterThanEqualTo ( s1 , s2 ) ) s1 = multiply ( s1 , temp ) ; return s1 == s2 ; } int main ( ) { string s1 = "374747" , s2 = "52627712618930723" ; cout << ( isPower ( s1 , s2 ) ? " YES STRNEWLINE " : " NO STRNEWLINE " ) ; s1 = "4099" , s2 = "2" ; cout << ( isPower ( s1 , s2 ) ? " YES STRNEWLINE " : " NO STRNEWLINE " ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, temp
Iterator variables: i, j
C++ program:
#include <stdio.h>
#include <stdlib.h>
int matchClosing ( char X [ ] , int start , int end , char open , char close ) { int c = 1 ; int i = start + 1 ; while ( i <= end ) { if ( X [ i ] == open ) c ++ ; else if ( X [ i ] == close ) c -- ; if ( c == 0 ) return i ; i ++ ; } return i ; } int matchingOpening ( char X [ ] , int start , int end , char open , char close ) { int c = -1 ; int i = end - 1 ; while ( i >= start ) { if ( X [ i ] == open ) c ++ ; else if ( X [ i ] == close ) c -- ; if ( c == 0 ) return i ; i -- ; } return -1 ; } bool isBalanced ( char X [ ] , int n ) { int i , j , k , x , start , end ; for ( i = 0 ; i < n ; i ++ ) { if ( X [ i ] == ' ( ' ) j = matchClosing ( X , i , n - 1 , ' ( ' , ' ) ' ) ; else if ( X [ i ] == ' { ' ) j = matchClosing ( X , i , n - 1 , ' { ' , ' } ' ) ; else if ( X [ i ] == ' [ ' ) j = matchClosing ( X , i , n - 1 , ' [ ' , ' ] ' ) ; else { if ( X [ i ] == ' ) ' ) j = matchingOpening ( X , 0 , i , ' ( ' , ' ) ' ) ; else if ( X [ i ] == ' } ' ) j = matchingOpening ( X , 0 , i , ' { ' , ' } ' ) ; else if ( X [ i ] == ' ] ' ) j = matchingOpening ( X , 0 , i , ' [ ' , ' ] ' ) ; if ( j < 0 j > = i ) return false ; continue ; } if ( j >= n j < 0 ) return false ; start = i ; end = j ; for ( k = start + 1 ; k < end ; k ++ ) { if ( X [ k ] == ' ( ' ) { x = matchClosing ( X , k , end , ' ( ' , ' ) ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ) ' ) { x = matchingOpening ( X , start , k , ' ( ' , ' ) ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } if ( X [ k ] == ' { ' ) { x = matchClosing ( X , k , end , ' { ' , ' } ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' } ' ) { x = matchingOpening ( X , start , k , ' { ' , ' } ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } if ( X [ k ] == ' [ ' ) { x = matchClosing ( X , k , end , ' [ ' , ' ] ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ] ' ) { x = matchingOpening ( X , start , k , ' [ ' , ' ] ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } } } return true ; } int main ( ) { char X [ ] = " [ ( ) ] ( ) " ; int n = 6 ; if ( isBalanced ( X , n ) ) printf ( " Yes STRNEWLINE " ) ; else printf ( " No STRNEWLINE " ) ; char Y [ ] = " [ [ ( ) ] ] ) " ; n = 7 ; if ( isBalanced ( Y , n ) ) printf ( " Yes STRNEWLINE " ) ; else printf ( " No STRNEWLINE " ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: c, i, k
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; string possibleToSort ( int * arr , int n , string str ) { int max_element = -1 ; for ( long i = 0 ; i < str . size ( ) ; i ++ ) { max_element = max ( max_element , arr [ i ] ) ; if ( str [ i ] == '0' ) { if ( max_element > i + 1 ) return " No " ; } } return " Yes " ; } int main ( ) { int arr [ ] = { 1 , 2 , 5 , 3 , 4 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; string str = "01110" ; cout << possibleToSort ( arr , n , str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define ll  long long int
using namespace std ; void findSubstring ( string str , ll power ) { ll i ; unordered_map < ll , ll > map ; int curr_power = 0 ; int len = str . length ( ) ; for ( i = 0 ; i < len ; i ++ ) { curr_power = curr_power + ( str [ i ] - ' a ' + 1 ) ; if ( curr_power == power ) { cout << " Substring ▁ from ▁ index ▁ " << 0 << " ▁ to ▁ " << i << " ▁ has ▁ power ▁ " << power << endl ; return ; } if ( map . find ( curr_power - power ) != map . end ( ) ) { cout << " Substring ▁ from ▁ index ▁ " << map [ curr_power - power ] + 1 << " ▁ to ▁ " << i << " ▁ has ▁ power ▁ " << power << endl ; return ; } map [ curr_power ] = i ; } cout << " No ▁ substring ▁ with ▁ given ▁ power ▁ exists . " ; } int main ( ) { string str = " geeksforgeeks " ; ll power = 36 ; findSubstring ( str , power ) ; return 0 ; }

Index/key variables: curr_power, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPrimeString ( string str ) { int len = str . length ( ) , n = 0 ; for ( int i = 0 ; i < len ; i ++ ) n += ( int ) str [ i ] ; if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } int main ( ) { string str = " geekRam " ; if ( isPrimeString ( str ) ) cout << " Yes " << endl ; else cout << " No " << endl ; }

Index/key variables: i
Accumulator variables: i, n, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWays ( string s ) { int count [ 26 ] = { 0 } ; for ( char x : s ) count [ x - ' a ' ] ++ ; count [ s [ 0 ] - ' a ' ] = 1 ; int ans = 1 ; for ( int i = 0 ; i < 26 ; ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ; return ans ; } int main ( ) { string s = " acbbcc " ; cout << countWays ( s ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void lexoString ( string s , int k ) { int n = s . size ( ) ; vector < char > v ; map < char , int > mp ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( mp [ s [ i ] ] == 0 ) { mp [ s [ i ] ] = 1 ; v . push_back ( s [ i ] ) ; } } sort ( v . begin ( ) , v . end ( ) ) ; if ( k > n ) { cout << s ; for ( int i = n ; i < k ; i ++ ) { cout << v [ 0 ] ; } } for ( int i = k - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != v [ v . size ( ) - 1 ] ) { for ( int j = 0 ; j < i ; j ++ ) { cout << s [ j ] ; } for ( int j = 0 ; j < v . size ( ) ; j ++ ) { if ( v [ j ] > s [ i ] ) { cout << v [ j ] ; break ; } } for ( int j = i + 1 ; j < k ; j ++ ) cout << v [ 0 ] ; return ; } } cout << " No ▁ lexicographically ▁ greater ▁ string ▁ of ▁ length ▁ " << k << " ▁ possible ▁ here . " ; } int main ( ) { string s = " gi " ; int k = 3 ; lexoString ( s , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 256 ; long long int fact ( int n ) { long long int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } int countPalinPermutations ( string & str ) { int n = str . length ( ) ; int freq [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] ] ++ ; long long int res = fact ( n / 2 ) ; bool oddFreq = false ; for ( int i = 0 ; i < MAX ; i ++ ) { int half = freq [ i ] / 2 ; if ( freq [ i ] % 2 != 0 ) { if ( oddFreq == true ) return 0 ; oddFreq = true ; } res = res / fact ( half ) ; } return res ; } int main ( ) { string str = " gffg " ; cout << countPalinPermutations ( str ) ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: oddFreq
C++ program:
#include <bits/stdc++.h>
using namespace std ; string getPalindrome ( string str ) { unordered_map < char , int > hmap ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) hmap [ str [ i ] ] ++ ; int oddCount = 0 ; char oddChar ; for ( auto x : hmap ) { if ( x . second % 2 != 0 ) { oddCount ++ ; oddChar = x . first ; } } if ( oddCount > 1 || oddCount == 1 && str . length ( ) % 2 == 0 ) return " NO ▁ PALINDROME " ; string firstHalf = " " , secondHalf = " " ; for ( auto x : hmap ) { string s ( x . second / 2 , x . first ) ; firstHalf = firstHalf + s ; secondHalf = s + secondHalf ; } return ( oddCount == 1 ) ? ( firstHalf + oddChar + secondHalf ) : ( firstHalf + secondHalf ) ; } int main ( ) { string s = " mdaam " ; cout << getPalindrome ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, oddCount, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char ch ) { return ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) ; } bool isCons ( char ch ) { return ( ch != ' a ' && ch != ' e ' && ch != ' i ' && ch != ' o ' && ch != ' u ' ) ; } int countSpecial ( string & str ) { int len = str . length ( ) ; if ( len == 0 ) return 0 ; int co [ len + 1 ] ; int vo [ len + 1 ] ; memset ( co , 0 , sizeof ( co ) ) ; memset ( vo , 0 , sizeof ( vo ) ) ; if ( isCons ( str [ len - 1 ] ) == 1 ) co [ len - 1 ] = 1 ; else vo [ len - 1 ] = 1 ; for ( int i = len - 2 ; i >= 0 ; i -- ) { if ( isCons ( str [ i ] ) == 1 ) { co [ i ] = co [ i + 1 ] + 1 ; vo [ i ] = vo [ i + 1 ] ; } else { co [ i ] = co [ i + 1 ] ; vo [ i ] = vo [ i + 1 ] + 1 ; } } long long ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( str [ i ] ) ) ans = ans + co [ i + 1 ] ; else ans = ans + vo [ i + 1 ] ; } return ans ; } int main ( ) { string str = " adceba " ; cout << countSpecial ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkPalindrome ( string str ) { int n = str . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; ++ i ) if ( str [ i ] != str [ n - i - 1 ] ) ++ count ; return ( count <= 1 ) ; } int main ( ) { string str = " abccaa " ; if ( checkPalindrome ( str ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int evenDecimalValue ( string str , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '0' ) { result += ( n - i ) ; } } return result ; } int main ( ) { string str = "10010" ; int n = 5 ; cout << evenDecimalValue ( str , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countSubstr ( string s ) { int n = s . length ( ) ; int auxArr [ n ] = { 0 } ; if ( s [ 0 ] == '1' ) auxArr [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == '1' ) auxArr [ i ] = auxArr [ i - 1 ] + 1 ; else auxArr [ i ] = auxArr [ i - 1 ] ; } int count = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) if ( s [ i ] == '1' ) count += auxArr [ i ] ; return count ; } int main ( ) { string s = "1101" ; cout << countSubstr ( s ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > findSubstringIndices ( string S , const vector < string > & L ) { int size_word = L [ 0 ] . size ( ) ; int word_count = L . size ( ) ; int size_L = size_word * word_count ; vector < int > res ; if ( size_L > S . size ( ) ) return res ; unordered_map < string , int > hash_map ; for ( int i = 0 ; i < word_count ; i ++ ) hash_map [ L [ i ] ] ++ ; for ( int i = 0 ; i <= S . size ( ) - size_L ; i ++ ) { unordered_map < string , int > temp_hash_map ( hash_map ) ; int j = i , count = word_count ; while ( j < i + size_L ) { string word = S . substr ( j , size_word ) ; if ( hash_map . find ( word ) == hash_map . end ( ) temp_hash_map [ word ] == 0 ) break ; else { temp_hash_map [ word ] -- ; count -- ; } j += size_word ; } if ( count == 0 ) res . push_back ( i ) ; } return res ; } int main ( ) { string S = " barfoothefoobarman " ; vector < string > L = { " foo " , " bar " } ; vector < int > indices = findSubstringIndices ( S , L ) ; for ( int i = 0 ; i < indices . size ( ) ; i ++ ) cout << indices [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, word
Accumulator variables: count, i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 256 ; bool canMakeStr2 ( string str1 , string str2 ) { int count [ MAX ] = { 0 } ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) count [ str1 [ i ] ] ++ ; for ( int i = 0 ; i < str2 . length ( ) ; i ++ ) { if ( count [ str2 [ i ] ] == 0 ) return false ; count [ str2 [ i ] ] -- ; } return true ; } int main ( ) { string str1 = " geekforgeeks " ; string str2 = " for " ; if ( canMakeStr2 ( str1 , str2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void finalPosition ( string move ) { int l = move . size ( ) ; int countUp = 0 , countDown = 0 ; int countLeft = 0 , countRight = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( move [ i ] == ' U ' ) countUp ++ ; else if ( move [ i ] == ' D ' ) countDown ++ ; else if ( move [ i ] == ' L ' ) countLeft ++ ; else if ( move [ i ] == ' R ' ) countRight ++ ; } cout << " Final ▁ Position : ▁ ( " << ( countRight - countLeft ) << " , ▁ " << ( countUp - countDown ) << " ) " << endl ; } int main ( ) { string move = " UDDLLRUUUDUURUDDUULLDRRRR " ; finalPosition ( move ) ; return 0 ; }

Index/key variables: i
Accumulator variables: countDown, countLeft, countRight, countUp, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxbalancedprefix ( char str [ ] , int n ) { int sum = 0 ; int maxi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ( ' ) sum += 1 ; else sum -= 1 ; if ( sum < 0 ) break ; if ( sum == 0 ) maxi = i + 1 ; } return maxi ; } int main ( ) { char str [ ] = " ( ( ( ) ( ) ) ( ) ) ( ( " ; int n = strlen ( str ) ; cout << maxbalancedprefix ( str , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int cost ( string str ) { int len = str . length ( ) ; int res = 0 ; for ( int i = 0 , j = len - 1 ; i < j ; i ++ , j -- ) if ( str [ i ] != str [ j ] ) res += min ( str [ i ] , str [ j ] ) - ' a ' + 1 ; return res ; } int main ( ) { string str = " abcdef " ; cout << cost ( str ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char c ) { return ( c == ' A ' c == ' E ' c == ' I ' c == ' O ' c == ' U ' c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } string pigLatin ( string s ) { int len = s . length ( ) ; int index = -1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( s [ i ] ) ) { index = i ; break ; } } if ( index == -1 ) return " - 1" ; return s . substr ( index ) + s . substr ( 0 , index ) + " ay " ; } int main ( ) { string str = pigLatin ( " graphic " ) ; if ( str == " - 1" ) cout << " No ▁ vowels ▁ found . ▁ Pig ▁ Latin ▁ not ▁ possible " ; else cout << str ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 256 ; bool isPresent ( string s , string q ) { int freq [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) freq [ s [ i ] ] ++ ; for ( int i = 0 ; i < q . length ( ) ; i ++ ) { freq [ q [ i ] ] -- ; if ( freq [ q [ i ] ] < 0 ) return false ; } return true ; } int main ( ) { string s = " abctd " ; string q = " cat " ; if ( isPresent ( s , q ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countReduce ( string & str ) { int n = str . length ( ) ; int res = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) res += abs ( str [ i ] - str [ n - i - 1 ] ) ; return res ; } int main ( ) { string str = " abcd " ; cout << countReduce ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include " bits / stdc + + . h "
using namespace std ; int calculate ( string s ) { int ans = 6 ; for ( int i = 0 ; i < 10 ; ++ i ) { for ( int j = 0 ; j < 10 ; ++ j ) { for ( int k = 0 ; k < 10 ; ++ k ) { for ( int l = 0 ; l < 10 ; ++ l ) { for ( int m = 0 ; m < 10 ; ++ m ) { for ( int n = 0 ; n < 10 ; ++ n ) { if ( i + j + k == l + m + n ) { int c = 0 ; if ( i != s [ 0 ] - '0' ) c ++ ; if ( j != s [ 1 ] - '0' ) c ++ ; if ( k != s [ 2 ] - '0' ) c ++ ; if ( l != s [ 3 ] - '0' ) c ++ ; if ( m != s [ 4 ] - '0' ) c ++ ; if ( n != s [ 5 ] - '0' ) c ++ ; if ( c < ans ) ans = c ; } } } } } } } return ans ; } int main ( ) { string s = "123456" ; cout << calculate ( s ) ; }

Accumulator variables: c
Iterator variables: i, j, k, l, m, n
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool makeAndCheckString ( vector < string > words , string str ) { int n = words . size ( ) ; bool first = false , second = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( words [ i ] == str ) return true ; if ( str [ 0 ] == words [ i ] [ 1 ] ) first = true ; if ( str [ 1 ] == words [ i ] [ 0 ] ) second = true ; if ( first && second ) return true ; } return false ; } int main ( ) { string str = " ya " ; vector < string > words = { " ah " , " oy " , " to " , " ha " } ; if ( makeAndCheckString ( words , str ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: first, second
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; string getBinaryRep ( int N , int num_of_bits ) { string r = " " ; num_of_bits -- ; while ( num_of_bits >= 0 ) { if ( N & ( 1 << num_of_bits ) ) r . append ( "1" ) ; else r . append ( "0" ) ; num_of_bits -- ; } return r ; } vector < string > NBitBinary ( int N ) { vector < string > r ; int first = 1 << ( N - 1 ) ; int last = first * 2 ; for ( int i = last - 1 ; i >= first ; -- i ) { int zero_cnt = 0 ; int one_cnt = 0 ; int t = i ; int num_of_bits = 0 ; while ( t ) { if ( t & 1 ) one_cnt ++ ; else zero_cnt ++ ; num_of_bits ++ ; t = t >> 1 ; } if ( one_cnt >= zero_cnt ) { bool all_prefix_match = true ; int msk = ( 1 << num_of_bits ) - 2 ; int prefix_shift = 1 ; while ( msk ) { int prefix = ( msk & i ) >> prefix_shift ; int prefix_one_cnt = 0 ; int prefix_zero_cnt = 0 ; while ( prefix ) { if ( prefix & 1 ) prefix_one_cnt ++ ; else prefix_zero_cnt ++ ; prefix = prefix >> 1 ; } if ( prefix_zero_cnt > prefix_one_cnt ) { all_prefix_match = false ; break ; } prefix_shift ++ ; msk = msk & ( msk << 1 ) ; } if ( all_prefix_match ) { r . push_back ( getBinaryRep ( i , num_of_bits ) ) ; } } } return r ; } int main ( ) { int n = 4 ; vector < string > results = NBitBinary ( n ) ; for ( int i = 0 ; i < results . size ( ) ; ++ i ) cout << results [ i ] << " ▁ " ; cout << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: num_of_bits, one_cnt, prefix_one_cnt, prefix_shift, prefix_zero_cnt, stdc, zero_cnt
Iterator variables: i
Boolean variables: all_prefix_match
C++ program:
#include " bits / stdc + + . h "
using namespace std ; void findWinner ( vector < string > & votes ) { unordered_map < string , int > mapObj ; for ( auto & str : votes ) { mapObj [ str ] ++ ; } int maxValueInMap = 0 ; string winner ; for ( auto & entry : mapObj ) { string key = entry . first ; int val = entry . second ; if ( val > maxValueInMap ) { maxValueInMap = val ; winner = key ; } else if ( val == maxValueInMap && winner > key ) winner = key ; } cout << winner << endl ; } int main ( ) { vector < string > votes = { " john " , " johnny " , " jackie " , " johnny " , " john " , " jackie " , " jamie " , " jamie " , " john " , " johnny " , " jamie " , " johnny " , " john " } ; findWinner ( votes ) ; return 0 ; }

Index/key variables: str
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkLuhn ( const string & cardNo ) { int nDigits = cardNo . length ( ) ; int nSum = 0 , isSecond = false ; for ( int i = nDigits - 1 ; i >= 0 ; i -- ) { int d = cardNo [ i ] - '0' ; if ( isSecond == true ) d = d * 2 ; nSum += d / 10 ; nSum += d % 10 ; isSecond = ! isSecond ; } return ( nSum % 10 == 0 ) ; } int main ( ) { string cardNo = "79927398713" ; if ( checkLuhn ( cardNo ) ) printf ( " This ▁ is ▁ a ▁ valid ▁ card " ) ; else printf ( " This ▁ is ▁ not ▁ a ▁ valid ▁ card " ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, nSum, stdc
Iterator variables: i
Boolean variables: isSecond