dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; string decToBin ( int n ) { if ( n == 0 ) return "0" ; string bin = " " ; while ( n > 0 ) { bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ; n >>= 1 ; } return bin ; } string convertBinToOct ( string bin ) { int l = bin . size ( ) ; for ( int i = 1 ; i <= ( 3 - l % 3 ) % 3 ; i ++ ) bin = '0' + bin ; unordered_map < string , char > bin_oct_map ; bin_oct_map [ "000" ] = '0' ; bin_oct_map [ "001" ] = '1' ; bin_oct_map [ "010" ] = '2' ; bin_oct_map [ "011" ] = '3' ; bin_oct_map [ "100" ] = '4' ; bin_oct_map [ "101" ] = '5' ; bin_oct_map [ "110" ] = '6' ; bin_oct_map [ "111" ] = '7' ; int i = 0 ; string octal = " " ; while ( 1 ) { octal += bin_oct_map [ bin . substr ( i , 3 ) ] ; i += 3 ; if ( i == bin . size ( ) ) break ; } return octal ; } string decToOctal ( int n ) { string bin = decToBin ( n ) ; return convertBinToOct ( bin ) ; } int main ( ) { int n = 151 ; cout << decToOctal ( n ) ; return 0 ; }

Accumulator variables: i, octal, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < string > splitStrings ( string str , char dl ) { string word = " " ; int num = 0 ; str = str + dl ; int l = str . size ( ) ; vector < string > substr_list ; for ( int i = 0 ; i < l ; i ++ ) { if ( str [ i ] != dl ) word = word + str [ i ] ; else { if ( ( int ) word . size ( ) != 0 ) substr_list . push_back ( word ) ; word = " " ; } } return substr_list ; } int main ( ) { string str = " geeks ; for ; geeks " ; char dl = ' ; ' ; vector < string > res = splitStrings ( str , dl ) ; for ( auto x : res ) cout << x << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; string constructPalin ( string str , int len ) { int i = 0 , j = len - 1 ; for ( ; i < j ; i ++ , j -- ) { if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ; else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) { str [ i ] = ' a ' ; str [ j ] = ' a ' ; continue ; } else if ( str [ i ] == ' * ' ) { str [ i ] = str [ j ] ; continue ; } else if ( str [ j ] == ' * ' ) { str [ j ] = str [ i ] ; continue ; } cout << " Not ▁ Possible " ; return " " ; } return str ; } int main ( ) { string str = " bca * xc * * b " ; int len = str . size ( ) ; cout << constructPalin ( str , len ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfDifferentSubstrings ( string s , string a , string b ) { int ans = 0 ; int ls = s . size ( ) , la = a . size ( ) , lb = b . size ( ) ; int x [ ls ] = { 0 } , y [ ls ] = { 0 } ; for ( int i = 0 ; i < ls ; i ++ ) { if ( s . substr ( i , la ) == a ) x [ i ] = 1 ; if ( s . substr ( i , lb ) == b ) y [ i ] = 1 ; } unordered_set < string > hash ; string curr_substr = " " ; for ( int i = 0 ; i < ls ; i ++ ) { if ( x [ i ] ) { for ( int j = i ; j < ls ; j ++ ) { if ( ! y [ j ] ) curr_substr += s [ j ] ; if ( y [ j ] ) { curr_substr += s . substr ( j , lb ) ; if ( hash . find ( curr_substr ) == hash . end ( ) ) ans ++ ; hash . insert ( curr_substr ) ; } } curr_substr = " " ; } } return ans ; } int main ( ) { string s = " codecppforfood " ; string begin = " c " ; string end = " d " ; cout << numberOfDifferentSubstrings ( s , begin , end ) << endl ; return 0 ; }

Index/key variables: i, j, ls
Accumulator variables: ans, curr_substr, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define max  100
using namespace std ; void carveCross ( string str ) { int n = str . length ( ) ; if ( n % 2 == 0 ) { cout << " Not ▁ possible . ▁ Please ▁ enter ▁ " << " odd ▁ length ▁ string . STRNEWLINE " ; } else { char arr [ max ] [ max ] ; int m = n / 2 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { arr [ i ] [ j ] = ' X ' ; } } for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] [ m ] = str [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { arr [ m ] [ i ] = str [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { cout << arr [ i ] [ j ] << " ▁ " ; } cout << " STRNEWLINE " ; } } } int main ( ) { string str = " PICTURE " ; carveCross ( str ) ; return 0 ; }

Index/key variables: i, j, m, max
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void generatestring ( int n ) { for ( int i = 0 ; i < n ; i ++ ) putchar ( i & 2 ? ' b ' : ' a ' ) ; puts ( " " ) ; } int main ( ) { int n = 5 ; generatestring ( n ) ; n = 8 ; generatestring ( n ) ; n = 10 ; generatestring ( n ) ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string subsequence ( string s , int binary , int len ) { string sub = " " ; for ( int j = 0 ; j < len ; j ++ ) if ( binary & ( 1 << j ) ) sub += s [ j ] ; return sub ; } void possibleSubsequences ( string s ) { map < int , set < string > > sorted_subsequence ; int len = s . size ( ) ; int limit = pow ( 2 , len ) ; for ( int i = 1 ; i <= limit - 1 ; i ++ ) { string sub = subsequence ( s , i , len ) ; sorted_subsequence [ sub . length ( ) ] . insert ( sub ) ; } for ( auto it : sorted_subsequence ) { cout << " Subsequences ▁ of ▁ length ▁ = ▁ " << it . first << " ▁ are : " << endl ; for ( auto ii : it . second ) cout << ii << " ▁ " ; cout << endl ; } } int main ( ) { string s = " aabc " ; possibleSubsequences ( s ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc, sub
Iterator variables: i, ii, it, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string subsequence ( string s , int binary ) { string sub = " " ; int pos ; while ( binary > 0 ) { pos = log2 ( binary & - binary ) + 1 ; sub = s [ pos - 1 ] + sub ; binary = ( binary & ~ ( 1 << ( pos - 1 ) ) ) ; } reverse ( sub . begin ( ) , sub . end ( ) ) ; return sub ; } void possibleSubsequences ( string s ) { map < int , set < string > > sorted_subsequence ; int len = s . size ( ) ; int limit = pow ( 2 , len ) ; for ( int i = 1 ; i <= limit - 1 ; i ++ ) { string sub = subsequence ( s , i ) ; sorted_subsequence [ sub . length ( ) ] . insert ( sub ) ; } for ( auto it : sorted_subsequence ) { cout << " Subsequences ▁ of ▁ length ▁ = ▁ " << it . first << " ▁ are : " << endl ; for ( auto ii : it . second ) cout << ii << " ▁ " ; cout << endl ; } } int main ( ) { string s = " aabc " ; possibleSubsequences ( s ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i, ii, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int remainder ( string str ) { int len = str . length ( ) ; int num , rem = 0 ; for ( int i = 0 ; i < len ; i ++ ) { num = rem * 10 + ( str [ i ] - '0' ) ; rem = num % 11 ; } return rem ; } int main ( ) { string str = "3435346456547566345436457867978" ; cout << remainder ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubseq ( string s ) { int n = s . length ( ) ; int pre_count_0 [ n + 2 ] ; int pre_count_1 [ n + 1 ] ; int post_count_0 [ n + 1 ] ; pre_count_0 [ 0 ] = 0 ; post_count_0 [ n + 1 ] = 0 ; pre_count_1 [ 0 ] = 0 ; for ( int j = 1 ; j <= n ; j ++ ) { pre_count_0 [ j ] = pre_count_0 [ j - 1 ] ; pre_count_1 [ j ] = pre_count_1 [ j - 1 ] ; post_count_0 [ n - j + 1 ] = post_count_0 [ n - j + 2 ] ; if ( s [ j - 1 ] == '0' ) pre_count_0 [ j ] ++ ; else pre_count_1 [ j ] ++ ; if ( s [ n - j ] == '0' ) post_count_0 [ n - j + 1 ] ++ ; } if ( pre_count_0 [ n ] == n pre_count_0 [ n ] == 0 ) return n ; int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = i ; j <= n ; j ++ ) ans = max ( pre_count_0 [ i - 1 ] + pre_count_1 [ j ] - pre_count_1 [ i - 1 ] + post_count_0 [ j + 1 ] , ans ) ; return ans ; } int main ( ) { string s = "000011100000" ; cout << longestSubseq ( s ) ; return 0 ; }

Index/key variables: j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool shouldSwap ( char str [ ] , int start , int curr ) { for ( int i = start ; i < curr ; i ++ ) if ( str [ i ] == str [ curr ] ) return 0 ; return 1 ; } void findPermutations ( char str [ ] , int index , int n ) { if ( index >= n ) { cout << str << endl ; return ; } for ( int i = index ; i < n ; i ++ ) { bool check = shouldSwap ( str , index , i ) ; if ( check ) { swap ( str [ index ] , str [ i ] ) ; findPermutations ( str , index + 1 , n ) ; swap ( str [ index ] , str [ i ] ) ; } } } int main ( ) { char str [ ] = " ABCA " ; int n = strlen ( str ) ; findPermutations ( str , 0 , n ) ; return 0 ; }

Index/key variables: curr, i, index
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <cstring>
#include <iostream>
using namespace std ; void findPermutations ( char str [ ] , int index , int n ) { if ( index >= n || ( index + 1 ) >= n ) { cout << str << endl ; return ; } findPermutations ( str , index + 1 , n ) ; swap ( str [ index ] , str [ index + 1 ] ) ; findPermutations ( str , index + 2 , n ) ; swap ( str [ index ] , str [ index + 1 ] ) ; } int main ( ) { char str [ ] = { "12345" } ; int n = strlen ( str ) ; findPermutations ( str , 0 , n ) ; return 0 ; }

Index/key variables: index
C++ program:
#include <bits/stdc++.h>
using namespace std ; string decodeMedianString ( string s ) { int l = s . length ( ) ; string s1 = " " ; bool isEven = ( l % 2 == 0 ) ? true : false ; for ( int i = 0 ; i < l ; i += 2 ) { if ( isEven ) { s1 = s [ i ] + s1 ; s1 += s [ i + 1 ] ; } else { if ( l - i > 1 ) { s1 += s [ i ] ; s1 = s [ i + 1 ] + s1 ; } else { s1 += s [ i ] ; } } } return s1 ; } int main ( ) { string s = " eekgs " ; cout << decodeMedianString ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, s1, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumChars ( string & str ) { int n = str . length ( ) ; int res = -1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) res = max ( res , abs ( j - i - 1 ) ) ; return res ; } int main ( ) { string str = " abba " ; cout << maximumChars ( str ) ; 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_CHAR = 256 ; int maximumChars ( string & str ) { int n = str . length ( ) ; int res = -1 ; int firstInd [ MAX_CHAR ] ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) firstInd [ i ] = -1 ; for ( int i = 0 ; i < n ; i ++ ) { int first_ind = firstInd [ str [ i ] ] ; if ( first_ind == -1 ) firstInd [ str [ i ] ] = i ; else res = max ( res , abs ( i - first_ind - 1 ) ) ; } return res ; } int main ( ) { string str = " abba " ; cout << maximumChars ( str ) ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isUnique ( int a [ ] , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; sum += n - 1 ; return ( sum == k ) ; } int main ( ) { int a [ ] = { 3 , 3 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int k = 12 ; if ( isUnique ( a , n , k ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string nextWord ( string s ) { if ( s == " " ) return " a " ; int i = s . length ( ) - 1 ; while ( s [ i ] == ' z ' && i >= 0 ) i -- ; if ( i == -1 ) s = s + ' a ' ; else s [ i ] ++ ; return s ; } int main ( ) { string str = " samez " ; cout << nextWord ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isValid ( string p ) { int n = p . length ( ) ; int c1 = 0 , c0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] == '0' ) c0 ++ ; if ( p [ i ] == '1' ) c1 ++ ; } return ( c0 == c1 ) ? true : false ; } int longestSub ( string s ) { int max_len = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( isValid ( s . substr ( i , j - i + 1 ) ) && max_len < j - i + 1 ) max_len = j - i + 1 ; } } return max_len ; } int main ( ) { string s = "101001000" ; cout << longestSub ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: c0, c1, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; void commonCharacters ( string str [ ] , int n ) { bool prim [ MAX_CHAR ] ; memset ( prim , true , sizeof ( prim ) ) ; for ( int i = 0 ; i < n ; i ++ ) { bool sec [ MAX_CHAR ] = { false } ; for ( int j = 0 ; str [ i ] [ j ] ; j ++ ) { if ( prim [ str [ i ] [ j ] - ' a ' ] ) sec [ str [ i ] [ j ] - ' a ' ] = true ; } memcpy ( prim , sec , MAX_CHAR ) ; } for ( int i = 0 ; i < 26 ; i ++ ) if ( prim [ i ] ) printf ( " % c ▁ " , i + ' a ' ) ; } int main ( ) { string str [ ] = { " geeksforgeeks " , " gemkstones " , " acknowledges " , " aguelikes " } ; int n = sizeof ( str ) / sizeof ( str [ 0 ] ) ; commonCharacters ( str , n ) ; return 0 ; }

Index/key variables: MAX_CHAR, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalindrome ( string & s , int i , int j ) { int p = j ; for ( int k = i ; k <= p ; k ++ ) { if ( s [ k ] != s [ p ] ) return false ; p -- ; } return true ; } int countWays ( string & s ) { int n = s . length ( ) ; int count = 0 ; if ( isPalindrome ( s , 0 , n - 1 ) ) { for ( int i = n / 2 ; i < n ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) count ++ ; else break ; } { count ++ ; } else } else { for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( s [ i ] != s [ n - 1 - i ] ) { int j = n - 1 - i ; if ( isPalindrome ( s , i , n - 2 - i ) ) { for ( int k = i - 1 ; k >= 0 ; k -- ) { if ( s [ k ] != s [ j ] ) break ; count ++ ; } count ++ ; } if ( isPalindrome ( s , i + 1 , n - 1 - i ) ) { for ( int k = n - i ; k < n ; k ++ ) { if ( s [ k ] != s [ i ] ) break ; count ++ ; } count ++ ; } break ; } } } return count ; } int main ( ) { string s = " abca " ; cout << countWays ( s ) << endl ; return 0 ; }

Index/key variables: i, j, k, p
Accumulator variables: count, i, k, p, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countOfSubstringWithKOnes ( string s , int K ) { int N = s . length ( ) ; int res = 0 ; int countOfOne = 0 ; int freq [ N + 1 ] = { 0 } ; freq [ 0 ] = 1 ; for ( int i = 0 ; i < N ; i ++ ) { countOfOne += ( s [ i ] - '0' ) ; if ( countOfOne >= K ) { res += freq [ countOfOne - K ] ; } freq [ countOfOne ] ++ ; } return res ; } int main ( ) { string s = "10010" ; int K = 1 ; cout << countOfSubstringWithKOnes ( s , K ) << endl ; return 0 ; }

Index/key variables: countOfOne, i
Accumulator variables: countOfOne, i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 256 ; void printDuo ( string & str ) { int countChar [ MAX_CHAR ] = { 0 } ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) countChar [ str [ i ] - ' a ' ] ++ ; string str1 = " " , str2 = " " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( countChar [ i ] > 1 ) str2 = str2 + ( char ) ( i + ' a ' ) ; else if ( countChar [ i ] == 1 ) str1 = str1 + ( char ) ( i + ' a ' ) ; } cout << " String ▁ with ▁ characters ▁ occurring ▁ " << " once : STRNEWLINE " ; cout << str1 << " STRNEWLINE " ; cout << " String ▁ with ▁ characters ▁ occurring ▁ " << " multiple ▁ times : STRNEWLINE " ; cout << str2 << " STRNEWLINE " ; } int main ( ) { string str = " lovetocode " ; printDuo ( str ) ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void reverse ( char num [ ] , int i , int j ) { while ( i < j ) { swap ( num [ i ] , num [ j ] ) ; i ++ ; j -- ; } } void nextPalin ( char num [ ] , int n ) { if ( n <= 3 ) { cout << " Not ▁ Possible " ; return ; } int mid = n / 2 - 1 ; int i , j ; for ( i = mid - 1 ; i >= 0 ; i -- ) if ( num [ i ] < num [ i + 1 ] ) break ; if ( i < 0 ) { cout << " Not ▁ Possible " ; return ; } int smallest = i + 1 ; for ( j = i + 2 ; j <= mid ; j ++ ) if ( num [ j ] > num [ i ] && num [ j ] <= num [ smallest ] ) smallest = j ; swap ( num [ i ] , num [ smallest ] ) ; swap ( num [ n - i - 1 ] , num [ n - smallest - 1 ] ) ; reverse ( num , i + 1 , mid ) ; if ( n % 2 == 0 ) reverse ( num , mid + 1 , n - i - 2 ) ; else reverse ( num , mid + 2 , n - i - 2 ) ; cout << " Next ▁ Palindrome : ▁ " << num ; } int main ( ) { char num [ ] = "4697557964" ; int n = strlen ( num ) ; nextPalin ( num , n ) ; return 0 ; }

Index/key variables: i, j, smallest
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printRec ( string number , int extraOnes , int remainingPlaces ) { if ( 0 == remainingPlaces ) { cout << number << " ▁ " ; return ; } printRec ( number + "1" , extraOnes + 1 , remainingPlaces - 1 ) ; if ( 0 < extraOnes ) printRec ( number + "0" , extraOnes - 1 , remainingPlaces - 1 ) ; } void printNums ( int n ) { string str = " " ; printRec ( str , 0 , n ) ; } int main ( ) { int n = 4 ; printNums ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findstem ( vector < string > arr ) { int n = arr . size ( ) ; string s = arr [ 0 ] ; int len = s . length ( ) ; string res = " " ; for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i + 1 ; j <= len ; j ++ ) { string stem = s . substr ( i , j ) ; int k = 1 ; for ( k = 1 ; k < n ; k ++ ) { if ( arr [ k ] . find ( stem ) == std :: string :: npos ) break ; } if ( k == n && res . length ( ) < stem . length ( ) ) res = stem ; } } return res ; } int main ( ) { vector < string > arr { " grace " , " graceful " , " disgraceful " , " gracefully " } ; string stems = findstem ( arr ) ; cout << stems << endl ; }

Index/key variables: k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 256 ; bool isPossible ( string & s1 , string & s2 ) { int count [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) count [ s2 [ i ] ] ++ ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( count [ s1 [ i ] ] == 0 ) return false ; count [ s1 [ i ] ] -- ; } return true ; } int main ( ) { string s1 = " GeeksforGeeks " , s2 = " rteksfoGrdsskGeggehes " ; if ( isPossible ( s1 , s2 ) ) cout << " Possible " ; else cout << " Not ▁ Possible STRNEWLINE " ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string nxtHighUsingAtMostOneSwap ( string num ) { int l = num . size ( ) ; int posRMax = l - 1 ; int index = -1 ; for ( int i = l - 2 ; i >= 0 ; i -- ) { if ( num [ i ] >= num [ posRMax ] ) posRMax = i ; else { index = i ; break ; } } if ( index == -1 ) return " Not ▁ Possible " ; int greatSmallDgt = -1 ; for ( int i = l - 1 ; i > index ; i -- ) { if ( num [ i ] > num [ index ] ) { if ( greatSmallDgt == -1 ) greatSmallDgt = i ; else if ( num [ i ] <= num [ greatSmallDgt ] ) greatSmallDgt = i ; } } char temp = num [ index ] ; num [ index ] = num [ greatSmallDgt ] ; num [ greatSmallDgt ] = temp ; return num ; } int main ( ) { string num = "218765" ; cout << " Original ▁ number : ▁ " << num << endl ; cout << " Next ▁ higher ▁ number : ▁ " << nxtHighUsingAtMostOneSwap ( num ) ; return 0 ; }

Index/key variables: greatSmallDgt, i, index, posRMax
Accumulator variables: i, 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 ' ) ; } int longestVowel ( string s ) { int count = 0 , res = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( isVowel ( s [ i ] ) ) count ++ ; else { res = max ( res , count ) ; count = 0 ; } } return max ( res , count ) ; } int main ( ) { string s = " theeare " ; cout << longestVowel ( s ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; bool check ( int freq [ ] , int k ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( freq [ i ] && freq [ i ] != k ) return false ; return true ; } int substrings ( string s , int k ) { for ( int i = 0 ; s [ i ] ; i ++ ) { int freq [ MAX_CHAR ] = { 0 } ; for ( int j = i ; s [ j ] ; j ++ ) { int index = s [ j ] - ' a ' ; freq [ index ] ++ ; if ( freq [ index ] > k ) break ; else if ( freq [ index ] == k && check ( freq , k ) == true ) res ++ ; } } return res ; } int main ( ) { string s = " aabbcc " ; int k = 2 ; cout << substrings ( s , k ) << endl ; s = " aabbc " ; k = 2 ; cout << substrings ( s , k ) << endl ; }

Index/key variables: MAX_CHAR, i, index, j
Accumulator variables: i, j, res, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <map>
#include <set>
#include <string>
int min ( int a , int b ) { return a < b ? a : b ; } using namespace std ; bool have_same_frequency ( map < char , int > & freq , int k ) { for ( auto & pair : freq ) { if ( pair . second != k && pair . second != 0 ) { return false ; } } return true ; } int count_substrings ( string s , int k ) { int count = 0 ; int distinct = ( set < char > ( s . begin ( ) , s . end ( ) ) ) . size ( ) ; for ( int length = 1 ; length <= distinct ; length ++ ) { int window_length = length * k ; map < char , int > freq ; int window_start = 0 ; int window_end = window_start + window_length - 1 ; for ( int i = window_start ; i <= min ( window_end , s . length ( ) - 1 ) ; i ++ ) { freq [ s [ i ] ] ++ ; } while ( window_end < s . length ( ) ) { if ( have_same_frequency ( freq , k ) ) { count ++ ; } freq [ s [ window_start ] ] -- ; window_start ++ ; window_end ++ ; if ( window_length < s . length ( ) ) { freq [ s [ window_end ] ] ++ ; } } } return count ; } int main ( ) { string s = " aabbcc " ; int k = 2 ; cout << count_substrings ( s , k ) << endl ; s = " aabbc " ; k = 2 ; cout << count_substrings ( s , k ) << endl ; return 0 ; }

Index/key variables: i, window_end, window_start
Accumulator variables: count, i, length, window_end, window_start
Iterator variables: i, length
C++ program:
#include <iostream>
using namespace std ; const int MAX_CHAR = 26 ; struct Trie { int cnt ; Trie * node [ MAX_CHAR ] ; Trie ( ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) node [ i ] = NULL ; cnt = 0 ; } } ; Trie * insert ( Trie * root , string s ) { Trie * temp = root ; int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int index = s [ i ] - ' a ' ; if ( ! root -> node [ index ] ) root -> node [ index ] = new Trie ( ) ; root = root -> node [ index ] ; } root -> cnt ++ ; return temp ; } int search ( Trie * root , string s ) { int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int index = s [ i ] - ' a ' ; if ( ! root -> node [ index ] ) return 0 ; root = root -> node [ index ] ; } return root -> cnt ; } void answerQueries ( string arr [ ] , int n , string q [ ] , int m ) { Trie * root = new Trie ( ) ; for ( int i = 0 ; i < n ; i ++ ) root = insert ( root , arr [ i ] ) ; for ( int i = 0 ; i < m ; i ++ ) cout << search ( root , q [ i ] ) << " ▁ " ; } int main ( ) { string arr [ ] = { " aba " , " baba " , " aba " , " xzxb " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; string q [ ] = { " aba " , " xzxb " , " ab " } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; answerQueries ( arr , n , q , m ) ; return 0 ; }

Index/key variables: MAX_CHAR, i, index
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: Trie