dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; class Solution { public : string remove_k_char ( int k , string s ) { if ( k == 1 ) return " " ; string output = " " ; stack < pair < char , int > > stk ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( stk . empty ( ) == true ) { stk . push ( make_pair ( s [ i ] , 1 ) ) ; } else { if ( s [ i ] == ( stk . top ( ) ) . first ) { stk . push ( { s [ i ] , stk . top ( ) . second + 1 } ) ; if ( stk . top ( ) . second == k ) { int x = k ; while ( x ) { stk . pop ( ) ; x -- ; } } } else { stk . push ( make_pair ( s [ i ] , 1 ) ) ; } } } while ( ! stk . empty ( ) ) { output += stk . top ( ) . first ; stk . pop ( ) ; } reverse ( output . begin ( ) , output . end ( ) ) ; return output ; } } ; int main ( ) { string s = " geeksforgeeks " ; int k = 2 ; Solution obj ; cout << obj . remove_k_char ( k , s ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, output, stdc, x
Iterator variables: i
Class/struct names: Solution
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define NO_OF_CHARS  256
int firstNonRepeating ( char * str ) { int arr [ NO_OF_CHARS ] ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) arr [ i ] = -1 ; for ( int i = 0 ; str [ i ] ; i ++ ) { if ( arr [ str [ i ] ] == -1 ) arr [ str [ i ] ] = i ; else arr [ str [ i ] ] = -2 ; } int res = INT_MAX ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( arr [ i ] >= 0 ) res = min ( res , arr [ i ] ) ; return res ; } int main ( ) { char str [ ] = " geeksforgeeks " ; int index = firstNonRepeating ( str ) ; if ( index == INT_MAX ) cout << " Either ▁ all ▁ characters ▁ are ▁ " " repeating ▁ or ▁ string ▁ is ▁ empty " ; else cout << " First ▁ non - repeating ▁ character " " ▁ is ▁ " << str [ index ] ; return 0 ; }

Index/key variables: NO_OF_CHARS, i, index
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string minimize ( string str ) { string mstr = " ▁ " ; int l , i , flagchar [ 26 ] = { 0 } ; char ch ; l = str . length ( ) ; for ( i = 0 ; i < str . length ( ) ; i ++ ) { ch = str . at ( i ) ; if ( flagchar [ ch - 97 ] == 0 ) { mstr = mstr + ch ; flagchar [ ch - 97 ] = 1 ; } } } void replaceMinimizeUtil ( string str ) { string minimizedStr , finalStr = " " ; int i , index , l ; char ch ; l = str . length ( ) ; for ( i = 0 ; i < minimizedStr . length ( ) ; i ++ ) { ch = minimizedStr . at ( i ) ; index = ( ch * ch ) % l ; finalStr = finalStr + str . at ( index ) ; } } int main ( ) { string str = " geeks " ; replaceMinimizeUtil ( str ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
void cipher ( char str [ ] ) { for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) { if ( isalpha ( str [ i ] ) == 0 && str [ i ] != ' ▁ ' ) { printf ( " Enter ▁ only ▁ alphabets ▁ and ▁ space STRNEWLINE " ) ; return ; } } printf ( " Encrypted ▁ Code ▁ using ▁ Latin ▁ Alphabet STRNEWLINE " ) ; for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) printf ( " % d ▁ " , str [ i ] - ' A ' + 1 ) ; else if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) printf ( " % d ▁ " , str [ i ] - ' a ' + 1 ) ; if ( str [ i ] == ' ▁ ' ) printf ( " % c " , str [ i ] ) ; } printf ( " STRNEWLINE " ) ; } int main ( ) { char str [ ] = " geeksforgeeks " ; cipher ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkPalin ( string word ) { int n = word . length ( ) ; transform ( word . begin ( ) , word . end ( ) , word . begin ( ) , :: tolower ) ; for ( int i = 0 ; i < n ; i ++ , n -- ) if ( word . at ( i ) != word . at ( n - 1 ) ) return false ; return true ; } int countPalin ( string str ) { str = str + " ▁ " ; string word = " " ; int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . at ( i ) ; if ( ch != ' ▁ ' ) word = word + ch ; else { if ( checkPalin ( word ) ) count ++ ; word = " " ; } } return count ; } int main ( ) { cout << countPalin ( " Madam ▁ Arora ▁ teaches ▁ malayalam " ) << endl ; cout << countPalin ( " Nitin ▁ speaks ▁ malayalam " ) << endl ; }

Accumulator variables: count, i, n, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool pre [ 100 ] ; int n ; string w ; string s [ 110 ] ; char letter ; void verify ( int position , int index ) { int l = w . length ( ) ; int k = s [ index ] . length ( ) ; if ( position + k > l ) return ; bool same = true ; for ( int i = position ; i < position + k ; i ++ ) { int n , n1 ; char ch = w [ i ] ; char ch1 = s [ index ] [ i - position ] ; if ( ch >= ' a ' && ch <= ' z ' ) n = ch - ' a ' ; else n = ch - ' A ' ; if ( ch1 >= ' a ' && ch1 <= ' z ' ) n1 = ch1 - ' a ' ; else n1 = ch1 - ' A ' ; if ( n != n1 ) same = false ; } if ( same == true ) { for ( int i = position ; i < position + k ; i ++ ) pre [ i ] = true ; return ; } } void solve ( ) { int l = w . length ( ) ; int p = letter - ' a ' ; for ( int i = 0 ; i < 100 ; i ++ ) pre [ i ] = false ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) verify ( i , j ) ; } for ( int i = 0 ; i < l ; i ++ ) { if ( pre [ i ] == true ) { if ( w [ i ] == letter ) w [ i ] = ( letter == ' a ' ) ? ' b ' : ' a ' ; else if ( w [ i ] == ' A ' + p ) w [ i ] = ( letter == ' a ' ) ? ' B ' : ' A ' ; else if ( w [ i ] >= ' a ' && w [ i ] <= ' z ' ) w [ i ] = letter ; else if ( w [ i ] >= ' A ' && w [ i ] <= ' Z ' ) w [ i ] = ' A ' + p ; } } cout << w ; } int main ( ) { n = 3 ; s [ 0 ] = " etr " ; s [ 1 ] = " ed " ; s [ 2 ] = " ied " ; w = " PEtrUnited " ; letter = ' d ' ; solve ( ) ; return 0 ; }

Index/key variables: i, index
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: same
C++ program:
#include <bits/stdc++.h>
using namespace std ; int round ( int n ) { int a = ( n / 10 ) * 10 ; int b = a + 10 ; return ( n - a > b - n ) ? b : a ; } int main ( ) { int n = 4722 ; cout << round ( n ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculate ( string N ) { int len = N . length ( ) ; int l = ( len ) / 2 ; int count = 0 ; for ( int i = 1 ; i <= l ; i ++ ) { string s = N . substr ( 0 , i ) ; int l1 = s . length ( ) ; string t = N . substr ( i , l1 ) ; if ( s [ 0 ] == '0' t [ 0 ] == '0' ) continue ; if ( s . compare ( t ) == 0 ) count ++ ; } return count ; } int main ( ) { string N = "2202200" ; cout << calculate ( N ) ; return 0 ; }

Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countOccurrences ( string s , int K ) { int n = s . length ( ) ; int C , c1 = 0 , c2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' a ' ) c1 ++ ; if ( s [ i ] == ' b ' ) { c2 ++ ; C += c1 ; } } return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ; } int main ( ) { string S = " abcb " ; int k = 2 ; cout << countOccurrences ( S , k ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: C, c1, c2, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printStrongNess ( string & input ) { int n = input . length ( ) ; bool hasLower = false , hasUpper = false ; bool hasDigit = false , specialChar = false ; string normalChars = " abcdefghijklmnopqrstu " " vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ▁ " ; for ( int i = 0 ; i < n ; i ++ ) { if ( islower ( input [ i ] ) ) hasLower = true ; if ( isupper ( input [ i ] ) ) hasUpper = true ; if ( isdigit ( input [ i ] ) ) hasDigit = true ; size_t special = input . find_first_not_of ( normalChars ) ; if ( special != string :: npos ) specialChar = true ; } cout << " Strength ▁ of ▁ password : - " ; if ( hasLower && hasUpper && hasDigit && specialChar && ( n >= 8 ) ) cout << " Strong " << endl ; else if ( ( hasLower hasUpper ) && specialChar && ( n >= 6 ) ) cout << " Moderate " << endl ; else cout << " Weak " << endl ; } int main ( ) { string input = " GeeksforGeeks ! @12" ; printStrongNess ( input ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: hasDigit, hasLower, hasUpper, specialChar
C++ program:
#include <iostream>
using namespace std ; string findString ( int n , int k ) { string res = " " ; for ( int i = 0 ; i < k ; i ++ ) res = res + ( char ) ( ' a ' + i ) ; int count = 0 ; for ( int i = 0 ; i < n - k ; i ++ ) { res = res + ( char ) ( ' a ' + count ) ; count ++ ; if ( count == k ) count = 0 ; } return res ; } int main ( ) { int n = 5 , k = 2 ; cout << findString ( n , k ) ; return 0 ; }

Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int getDigit ( int number ) { if ( number < 9 ) return number ; return number / 10 + number % 10 ; } int getSize ( long d ) { string num = to_string ( d ) ; return num . length ( ) ; } long getPrefix ( long number , int k ) { if ( getSize ( number ) > k ) { string num = to_string ( number ) ; return stol ( num . substr ( 0 , k ) ) ; } return number ; } bool prefixMatched ( long number , int d ) { return getPrefix ( number , getSize ( d ) ) == d ; } int sumOfDoubleEvenPlace ( long int number ) { int sum = 0 ; string num = to_string ( number ) ; for ( int i = getSize ( number ) - 2 ; i >= 0 ; i -= 2 ) sum += getDigit ( int ( num [ i ] - '0' ) * 2 ) ; return sum ; } int sumOfOddPlace ( long number ) { int sum = 0 ; string num = to_string ( number ) ; for ( int i = getSize ( number ) - 1 ; i >= 0 ; i -= 2 ) sum += num [ i ] - '0' ; return sum ; } bool isValid ( long int number ) { return ( getSize ( number ) >= 13 && getSize ( number ) <= 16 ) && ( prefixMatched ( number , 4 ) || prefixMatched ( number , 5 ) || prefixMatched ( number , 37 ) || prefixMatched ( number , 6 ) ) && ( ( sumOfDoubleEvenPlace ( number ) + sumOfOddPlace ( number ) ) % 10 == 0 ) ; } int main ( ) { long int number = 5196081888500645L ; cout << number << " ▁ is ▁ " << ( isValid ( number ) ? " valid " : " invalid " ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } void FindSubstring ( string str ) { int start = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( isVowel ( str [ i ] ) == true ) { hash . insert ( str [ i ] ) ; if ( hash . size ( ) == 5 ) cout << str . substr ( start , i - start + 1 ) << " ▁ " ; } else { start = i + 1 ; hash . clear ( ) ; } } } int main ( ) { string str = " aeoibsddaeiouudb " ; FindSubstring ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string concatenetedString ( string s1 , string s2 ) { unordered_map < char , int > m ; for ( int i = 0 ; i < s2 . size ( ) ; i ++ ) m [ s2 [ i ] ] = 1 ; for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( m . find ( s1 [ i ] ) == m . end ( ) ) res += s1 [ i ] ; else m [ s1 [ i ] ] = 2 ; } for ( int i = 0 ; i < s2 . size ( ) ; i ++ ) if ( m [ s2 [ i ] ] == 1 ) res += s2 [ i ] ; return res ; } int main ( ) { string s1 = " abcs " ; string s2 = " cxzca " ; cout << concatenetedString ( s1 , s2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; set < string > st ; bool isVowel ( char c ) { return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) ; } bool isConsonant ( char c ) { return ! isVowel ( c ) ; } void subsequence ( string str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( isVowel ( str [ i ] ) ) { for ( int j = str . length ( ) - 1 ; j >= i ; j -- ) { if ( isConsonant ( str [ j ] ) ) { string str_sub = str . substr ( i , j + 1 ) ; st . insert ( str_sub ) ; for ( int k = 1 ; k < str_sub . length ( ) - 1 ; k ++ ) { string sb = str_sub ; sb . erase ( sb . begin ( ) + k ) ; subsequence ( sb ) ; } } } } } } int main ( ) { string s = " xabcef " ; subsequence ( s ) ; for ( auto i : st ) cout << i << " ▁ " ; cout << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; string decode ( string str ) { string res = " " ; bool found = false ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { if ( str [ i ] == ' ▁ ' ) { found = false ; continue ; } if ( ! found ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { res += str [ i ] + 32 ; found = true ; } else if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) { res += str [ i ] ; found = true ; } } } return res ; } int main ( ) { string in ; in = " A ▁ Step ▁ by ▁ Step ▁ Guide ▁ for ▁ Placement ▁ Preparation ▁ by ▁ GeeksforGeeks " ; cout << " Enciphered ▁ Message : ▁ " ; cout << decode ( in ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
Boolean variables: found
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHARS = 256 ; string findSubString ( string str ) { int n = str . length ( ) ; int dist_count = 0 ; unordered_map < int , int > hash_map ; for ( int i = 0 ; i < n ; i ++ ) { hash_map [ str [ i ] ] ++ ; } dist_count = hash_map . size ( ) ; int size = INT_MAX ; string res ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; int visited [ 256 ] = { 0 } ; string sub_str = " " ; for ( int j = i ; j < n ; j ++ ) { if ( visited [ str [ j ] ] == 0 ) { count ++ ; visited [ str [ j ] ] = 1 ; } sub_str += str [ j ] ; if ( count == dist_count ) break ; } if ( sub_str . length ( ) < size && count == dist_count ) { res = sub_str ; size = res . length ( ) ; } } return res ; } int main ( ) { string str = " aabcbcdbca " ; cout << " Smallest ▁ window ▁ containing ▁ all ▁ distinct " " ▁ characters ▁ is : ▁ " << findSubString ( str ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc, sub_str
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printRotatedString ( char str [ ] ) { int n = strlen ( str ) ; char temp [ 2 * n + 1 ] ; strcpy ( temp , str ) ; strcat ( temp , str ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j != n ; j ++ ) printf ( " % c " , temp [ i + j ] ) ; printf ( " STRNEWLINE " ) ; } } int main ( ) { char str [ ] = " geeks " ; printRotatedString ( str ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define M  26
int getIdx ( char ch ) { return ( ch - ' a ' ) ; } bool allSame ( int freq [ ] , int N ) { int same ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( freq [ i ] > 0 ) { same = freq [ i ] ; break ; } } for ( int j = i + 1 ; j < N ; j ++ ) if ( freq [ j ] > 0 && freq [ j ] != same ) return false ; return true ; } bool possibleSameCharFreqByOneRemoval ( string str ) { int l = str . length ( ) ; int freq [ M ] = { 0 } ; for ( int i = 0 ; i < l ; i ++ ) freq [ getIdx ( str [ i ] ) ] ++ ; if ( allSame ( freq , M ) ) return true ; for ( char c = ' a ' ; c <= ' z ' ; c ++ ) { int i = getIdx ( c ) ; if ( freq [ i ] > 0 ) { freq [ i ] -- ; if ( allSame ( freq , M ) ) return true ; freq [ i ] ++ ; } } return false ; } int main ( ) { string str = " xyyzz " ; if ( possibleSameCharFreqByOneRemoval ( str ) ) cout << " Yes " ; else cout << " No " ; }

Index/key variables: M, i, j
Accumulator variables: c, i, j, stdc
Iterator variables: c, i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int check ( string str ) { int n = str . length ( ) ; int oddDigSum = 0 , evenDigSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ; else evenDigSum += ( str [ i ] - '0' ) ; } return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ; } int main ( ) { string str = "76945" ; check ( str ) ? cout << " Yes " : cout << " No ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: evenDigSum, i, oddDigSum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ARRAY_SIZE ( a )  sizeof(a)/sizeof(a[0])
#define ALPHABET_SIZE  (26)
#define CHAR_TO_INDEX ( c )  ((int)c - (int)'a')
struct TrieNode { struct TrieNode * children [ ALPHABET_SIZE ] ; int id ; bool isLeaf ; } ; struct TrieNode * getNode ( void ) { struct TrieNode * pNode = new TrieNode ; pNode -> isLeaf = false ; for ( int i = 0 ; i < ALPHABET_SIZE ; i ++ ) pNode -> children [ i ] = NULL ; return pNode ; } bool isPalindrome ( string str , int i , int len ) { while ( i < len ) { if ( str [ i ] != str [ len ] ) return false ; i ++ , len -- ; } return true ; } void insert ( struct TrieNode * root , string key , int id ) { struct TrieNode * pCrawl = root ; for ( int level = key . length ( ) - 1 ; level >= 0 ; level -- ) { int index = CHAR_TO_INDEX ( key [ level ] ) ; if ( ! pCrawl -> children [ index ] ) pCrawl -> children [ index ] = getNode ( ) ; if ( isPalindrome ( key , 0 , level ) ) ( pCrawl -> pos ) . push_back ( id ) ; pCrawl = pCrawl -> children [ index ] ; } pCrawl -> id = id ; pCrawl -> pos . push_back ( id ) ; pCrawl -> isLeaf = true ; } void search ( struct TrieNode * root , string key , int id , vector < vector < int > > & result ) { struct TrieNode * pCrawl = root ; for ( int level = 0 ; level < key . length ( ) ; level ++ ) { int index = CHAR_TO_INDEX ( key [ level ] ) ; if ( pCrawl -> id >= 0 && pCrawl -> id != id && isPalindrome ( key , level , key . size ( ) - 1 ) ) result . push_back ( { id , pCrawl -> id } ) ; if ( ! pCrawl -> children [ index ] ) return ; pCrawl = pCrawl -> children [ index ] ; } for ( int i : pCrawl -> pos ) { if ( i == id ) continue ; result . push_back ( { id , i } ) ; } } bool checkPalindromePair ( vector < string > vect ) { struct TrieNode * root = getNode ( ) ; for ( int i = 0 ; i < vect . size ( ) ; i ++ ) insert ( root , vect [ i ] , i ) ; vector < vector < int > > result ; for ( int i = 0 ; i < vect . size ( ) ; i ++ ) { search ( root , vect [ i ] , i , result ) ; if ( result . size ( ) > 0 ) return true ; } return false ; } int main ( ) { vector < string > vect = { " geekf " , " geeks " , " or " , " keeg " , " abc " , " bc " } ; checkPalindromePair ( vect ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Index/key variables: ALPHABET_SIZE, i, index, len, level
Accumulator variables: i, len, level, stdc
Iterator variables: i, level
Boolean variables: isLeaf
Class/struct names: TrieNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; int hammingDist ( char * str1 , char * str2 ) { int i = 0 , count = 0 ; while ( str1 [ i ] != ' \0' ) { if ( str1 [ i ] != str2 [ i ] ) count ++ ; i ++ ; } return count ; } int main ( ) { char str1 [ ] = " geekspractice " ; char str2 [ ] = " nerdspractise " ; cout << hammingDist ( str1 , str2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; bool arekAnagrams ( string str1 , string str2 , int k ) { int n = str1 . length ( ) ; if ( str2 . length ( ) != n ) return false ; int count1 [ MAX_CHAR ] = { 0 } ; int count2 [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count1 [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) count2 [ str2 [ i ] - ' a ' ] ++ ; int count = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( count1 [ i ] > count2 [ i ] ) count = count + abs ( count1 [ i ] - count2 [ i ] ) ; return ( count <= k ) ; } int main ( ) { string str1 = " anagram " ; string str2 = " grammar " ; int k = 2 ; if ( arekAnagrams ( str1 , str2 , k ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void removeSpaces ( char * str ) { int count = 0 ; for ( int i = 0 ; str [ i ] ; i ++ ) if ( str [ i ] != ' ▁ ' ) str [ count ] = ' \0' ; } int main ( ) { char str [ ] = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " ; removeSpaces ( str ) ; cout << str ; return 0 ; }

Index/key variables: count, i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countSubStr ( char str [ ] ) { for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) { if ( str [ i ] == '1' ) m ++ ; } return m * ( m - 1 ) / 2 ; } int main ( ) { char str [ ] = "00100101" ; cout << countSubStr ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, m
Iterator variables: i
C++ program:
#include <iostream>
#include <cstring>
using namespace std ; int count9s ( char number [ ] ) { int n = strlen ( number ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( number [ i ] == '9' ) count ++ ; for ( int j = i + 1 ; j < n ; j ++ ) { sum = ( sum + number [ j ] - '0' ) % 9 ; if ( sum == 0 ) count ++ ; } } return count ; } int main ( ) { cout << count9s ( "4189" ) << endl ; cout << count9s ( "1809" ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
C++ program:
#include <iostream>
#include <string>
#include <vector>
using namespace std ; void generateGrayarr ( int n ) { if ( n <= 0 ) return ; vector < string > arr ; arr . push_back ( "0" ) ; arr . push_back ( "1" ) ; int i , j ; for ( i = 2 ; i < ( 1 << n ) ; i = i << 1 ) { for ( j = i - 1 ; j >= 0 ; j -- ) arr . push_back ( arr [ j ] ) ; for ( j = 0 ; j < i ; j ++ ) arr [ j ] = "0" + arr [ j ] ; for ( j = i ; j < 2 * i ; j ++ ) arr [ j ] = "1" + arr [ j ] ; } for ( i = 0 ; i < arr . size ( ) ; i ++ ) cout << arr [ i ] << endl ; } int main ( ) { generateGrayarr ( 3 ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void divide ( string str , int n ) { if ( str . length ( ) % n != 0 ) { cout << " Invalid ▁ Input : ▁ String ▁ size " ; cout << " ▁ is ▁ not ▁ divisible ▁ by ▁ n " ; return ; } int parts = str . length ( ) / n ; int start = 0 ; while ( start < str . length ( ) ) { cout << str . substr ( start , parts ) << endl ; start += parts ; } } int main ( ) { string str = " a _ simple _ divide _ string _ quest " ; divide ( str , 4 ) ; }

Accumulator variables: start
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > countMap ; int cnt = INT_MAX ; void count ( int curCnt , int pos , vector < int > charAvailable , string target , vector < string > stickers ) { if ( curCnt >= cnt ) return ; int m = stickers . size ( ) ; int n = target . size ( ) ; if ( pos == n ) { cnt = min ( cnt , curCnt ) ; return ; } char c = target [ pos ] ; if ( charAvailable > 0 ) { charAvailable -- ; count ( curCnt , pos + 1 , charAvailable , target , stickers ) ; charAvailable ++ ; } else { for ( int i = 0 ; i < m ; i ++ ) { if ( countMap [ i ] == 0 ) continue ; for ( int j = 0 ; j < 26 ; j ++ ) { charAvailable [ j ] += countMap [ i ] [ j ] ; } count ( curCnt + 1 , pos , charAvailable , target , stickers ) ; for ( int j = 0 ; j < 26 ; j ++ ) { charAvailable [ j ] -= countMap [ i ] [ j ] ; } } } } int minStickers ( vector < string > stickers , string target ) { if ( target == " " ) return -1 ; if ( target . size ( ) == 0 ) return 0 ; if ( stickers . size ( ) == 0 ) return -1 ; int m = stickers . size ( ) ; countMap . resize ( m , vector < int > ( 26 , 0 ) ) ; for ( int i = 0 ; i < stickers . size ( ) ; i ++ ) { string s = stickers [ i ] ; for ( char c : s ) { countMap [ i ] ++ ; } } vector < int > temp ( 26 ) ; count ( 0 , 0 , temp , target , stickers ) ; return cnt == INT_MAX ? -1 : cnt ; } int main ( ) { vector < string > str = { " with " , " example " , " science " } ; string target = " thehat " ; int Result = minStickers ( str , target ) ; cout << Result ; }

Index/key variables: i, j, pos
Accumulator variables: charAvailable, i, j, stdc
Iterator variables: c, i, j