dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printAll ( string str ) { int n = str . length ( ) ; unsigned int opsize = pow ( 2 , n ) ; for ( int counter = 1 ; counter < opsize ; counter ++ ) { string subs = " " ; for ( int j = 0 ; j < n ; j ++ ) { if ( counter & ( 1 << j ) ) subs . push_back ( str [ j ] ) ; } do { cout << subs << " ▁ " ; } while ( next_permutation ( subs . begin ( ) , subs . end ( ) ) ) ; } } int main ( ) { string str = " abc " ; printSubsequences ( str ) ; return 0 ; }

Index/key variables: j
Accumulator variables: counter, j, stdc
Iterator variables: counter, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalindrome ( string str ) { int n = str . size ( ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) if ( str . at ( i ) != str . at ( n - i - 1 ) ) return false ; return true ; } int maxLengthNonPalinSubstring ( string str ) { int n = str . size ( ) ; char ch = str . at ( 0 ) ; int i = 1 ; for ( i = 1 ; i < n ; i ++ ) if ( str . at ( i ) != ch ) break ; if ( i == n ) return 0 ; if ( isPalindrome ( str ) ) return n - 1 ; return n ; } int main ( ) { string str = " abba " ; cout << " Maximum ▁ length ▁ = ▁ " << maxLengthNonPalinSubstring ( str ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void moveSpaceInFront ( char str [ ] ) { int i = strlen ( str ) - 1 ; for ( int j = i ; j >= 0 ; j -- ) if ( str [ j ] != ' ▁ ' ) swap ( str [ i -- ] , str [ j ] ) ; } int main ( ) { char str [ ] = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " ; moveSpaceInFront ( str ) ; cout << str ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void moveSpaceInFront ( char str [ ] ) { int i = strlen ( str ) ; for ( int j = i ; j >= 0 ; j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ; while ( i >= 0 ) str [ i -- ] = ' ▁ ' ; } int main ( ) { char str [ ] = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " ; moveSpaceInFront ( str ) ; cout << str ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: j
C++ program:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool isPalindrome ( char * str ) { int len = strlen ( str ) ; if ( len == 1 ) return true ; char * ptr1 = str ; char * ptr2 = str + len - 1 ; while ( ptr2 > ptr1 ) { if ( * ptr1 != * ptr2 ) return false ; ptr1 ++ ; ptr2 -- ; } return true ; } int noOfAppends ( char s [ ] ) { if ( isPalindrome ( s ) ) return 0 ; s ++ ; return 1 + noOfAppends ( s ) ; } int main ( ) { char s [ ] = " abede " ; printf ( " % d STRNEWLINE " , noOfAppends ( s ) ) ; return 0 ; }

Accumulator variables: ptr1, ptr2, s
C++ program:
#include <bits/stdc++.h>
using namespace std ; int titleToNumber ( string s ) { int result = 0 ; for ( const auto & c : s ) { result *= 26 ; result += c - ' A ' + 1 ; } return result ; } int main ( ) { cout << titleToNumber ( " CDA " ) << endl ; return 0 ; }

Accumulator variables: result, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string reversingString ( string str , int start , int end ) { while ( start < end ) { str [ start ] ^= str [ end ] ; str [ end ] ^= str [ start ] ; str [ start ] ^= str [ end ] ; ++ start ; -- end ; } return str ; } int main ( ) { string s = " GeeksforGeeks " ; cout << reversingString ( s , 0 , 12 ) ; return 0 ; }

Index/key variables: end, start
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
#define MAX  100002
using namespace std ; int f ( int i , int m , char s [ ] , int memoize [ ] [ 3 ] ) { if ( i == strlen ( s ) ) return 0 ; if ( memoize [ i ] [ m ] != -1 ) return memoize [ i ] [ m ] ; int x = s [ i ] - '0' ; int ans = ( ( x + m ) % 3 == 0 && x % 2 == 0 ) + f ( i + 1 , ( m + x ) % 3 , s , memoize ) ; return memoize [ i ] [ m ] = ans ; } int countDivBy6 ( char s [ ] ) { int n = strlen ( s ) ; int memoize [ n + 1 ] [ 3 ] ; memset ( memoize , -1 , sizeof memoize ) ; int ans = 0 ; for ( int i = 0 ; i < strlen ( s ) ; i ++ ) { if ( s [ i ] == '0' ) ans ++ ; else ans += f ( i , 0 , s , memoize ) ; } return ans ; } int main ( ) { char s [ ] = "4806" ; cout << countDivBy6 ( s ) << endl ; return 0 ; }

Index/key variables: i, m
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const char MAX_CHAR = 26 ; void countFreq ( string str , int freq [ ] , int len ) { for ( int i = 0 ; i < len ; i ++ ) freq [ str . at ( i ) - ' a ' ] ++ ; } bool canMakePalindrome ( int freq [ ] , int len ) { int count_odd = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( freq [ i ] % 2 != 0 ) count_odd ++ ; if ( len % 2 == 0 ) { if ( count_odd > 0 ) return false ; else return true ; } if ( count_odd != 1 ) return false ; return true ; } string findOddAndRemoveItsFreq ( int freq [ ] ) { string odd_str = " " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( freq [ i ] % 2 != 0 ) { freq [ i ] -- ; odd_str = odd_str + ( char ) ( i + ' a ' ) ; return odd_str ; } } return odd_str ; } string findPalindromicString ( string str ) { int len = str . length ( ) ; int freq [ MAX_CHAR ] = { 0 } ; countFreq ( str , freq , len ) ; if ( ! canMakePalindrome ( freq , len ) ) return " No ▁ Palindromic ▁ String " ; string odd_str = findOddAndRemoveItsFreq ( freq ) ; string front_str = " " , rear_str = " ▁ " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { string temp = " " ; if ( freq [ i ] != 0 ) { char ch = ( char ) ( i + ' a ' ) ; for ( int j = 1 ; j <= freq [ i ] / 2 ; j ++ ) temp = temp + ch ; front_str = front_str + temp ; rear_str = temp + rear_str ; } } return ( front_str + odd_str + rear_str ) ; } int main ( ) { string str = " malayalam " ; cout << findPalindromicString ( str ) ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: count_odd, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int checkEquality ( string s ) { return ( s [ 0 ] == s [ s . size ( ) - 1 ] ) ; } int countSubstringWithEqualEnds ( string s ) { int result = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) if ( checkEquality ( s . substr ( i , len ) ) ) result ++ ; return result ; } int main ( ) { string s ( " abcab " ) ; cout << countSubstringWithEqualEnds ( s ) ; return 0 ; }

Accumulator variables: i, len, result, stdc
Iterator variables: i, len
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubstringWithEqualEnds ( string s ) { int result = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i ; j < n ; j ++ ) if ( s [ i ] == s [ j ] ) result ++ ; return result ; } int main ( ) { string s ( " abcab " ) ; cout << countSubstringWithEqualEnds ( s ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, result, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_DIGITS = 6 ; int getValue ( const string & str , int i , int m ) { if ( i + m > str . length ( ) ) return -1 ; int value = 0 ; for ( int j = 0 ; j < m ; j ++ ) { int c = str [ i + j ] - '0' ; if ( c < 0 c > 9 ) return -1 ; value = value * 10 + c ; } return value ; } int findMissingNumber ( const string & str ) { for ( int m = 1 ; m <= MAX_DIGITS ; ++ m ) { int n = getValue ( str , 0 , m ) ; if ( n == -1 ) break ; int missingNo = -1 ; bool fail = false ; for ( int i = m ; i != str . length ( ) ; i += 1 + log10l ( n ) ) { if ( ( missingNo == -1 ) && ( getValue ( str , i , 1 + log10l ( n + 2 ) ) == n + 2 ) ) { missingNo = n + 1 ; n += 2 ; } else if ( getValue ( str , i , 1 + log10l ( n + 1 ) ) == n + 1 ) n ++ ; else { fail = true ; break ; } } if ( ! fail ) return missingNo ; } } int main ( ) { cout << findMissingNumber ( "99101102" ) ; return 0 ; }

Accumulator variables: i, j, n, stdc
Iterator variables: i, j, m
Boolean variables: fail
C++ program:
#include <bits/stdc++.h>
using namespace std ; char maxRepeating ( string str ) { int len = str . length ( ) ; int count = 0 ; char res = str [ 0 ] ; for ( int i = 0 ; i < len ; i ++ ) { int cur_count = 1 ; for ( int j = i + 1 ; j < len ; j ++ ) { if ( str [ i ] != str [ j ] ) break ; cur_count ++ ; } if ( cur_count > count ) { count = cur_count ; res = str [ i ] ; } } return res ; } int main ( ) { string str = " aaaabbaaccde " ; cout << maxRepeating ( str ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: cur_count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findSum ( string str1 , string str2 ) { if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ; string str = " " ; int n1 = str1 . length ( ) , n2 = str2 . length ( ) ; reverse ( str1 . begin ( ) , str1 . end ( ) ) ; reverse ( str2 . begin ( ) , str2 . end ( ) ) ; int carry = 0 ; for ( int i = 0 ; i < n1 ; i ++ ) { int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ; str . push_back ( sum % 10 + '0' ) ; carry = sum / 10 ; } for ( int i = n1 ; i < n2 ; i ++ ) { int sum = ( ( str2 [ i ] - '0' ) + carry ) ; str . push_back ( sum % 10 + '0' ) ; carry = sum / 10 ; } if ( carry ) str . push_back ( carry + '0' ) ; reverse ( str . begin ( ) , str . end ( ) ) ; return str ; } int main ( ) { string str1 = "12" ; string str2 = "198111" ; cout << findSum ( str1 , str2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findSum ( string str1 , string str2 ) { if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ; string str = " " ; int n1 = str1 . length ( ) , n2 = str2 . length ( ) ; int diff = n2 - n1 ; int carry = 0 ; for ( int i = n1 - 1 ; i >= 0 ; i -- ) { int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i + diff ] - '0' ) + carry ) ; str . push_back ( sum % 10 + '0' ) ; carry = sum / 10 ; } for ( int i = n2 - n1 - 1 ; i >= 0 ; i -- ) { int sum = ( ( str2 [ i ] - '0' ) + carry ) ; str . push_back ( sum % 10 + '0' ) ; carry = sum / 10 ; } if ( carry ) str . push_back ( carry + '0' ) ; reverse ( str . begin ( ) , str . end ( ) ) ; return str ; } int main ( ) { string str1 = "12" ; string str2 = "198111" ; cout << findSum ( str1 , str2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalindrome ( string str ) { int len = str . length ( ) ; for ( int i = 0 ; i < len / 2 ; i ++ ) if ( str [ i ] != str [ len - i - 1 ] ) return false ; return true ; } bool checkPalindromePair ( vector < string > vect ) { for ( int i = 0 ; i < vect . size ( ) - 1 ; i ++ ) { for ( int j = i + 1 ; j < vect . size ( ) ; j ++ ) { string check_str ; check_str = vect [ i ] + vect [ j ] ; if ( isPalindrome ( check_str ) ) return true ; check_str = vect [ j ] + vect [ i ] ; if ( isPalindrome ( check_str ) ) 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: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void print ( string str ) { cout << str [ 0 ] ; for ( int i = 1 ; str [ i ] != ' \0' ; i ++ ) { if ( ( str [ i ] == str [ i - 1 ] + 1 ) || ( str [ i ] == str [ i - 1 ] - 1 ) ) cout << str [ i ] ; else cout << " STRNEWLINE " << str [ i ] ; ; } } int main ( ) { string str = " ABCXYZACCD " ; print ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool areChractersUnique ( string str ) { int checker = 0 ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { int val = ( str [ i ] - ' a ' ) ; if ( ( checker & ( 1 << val ) ) > 0 ) return false ; checker |= ( 1 << val ) ; } return true ; } int main ( ) { string s = " aaabbccdaa " ; if ( areChractersUnique ( s ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: checker, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWords ( char str [ ] , int len ) { int count = 1 ; if ( len == 1 ) return count ; if ( str [ 0 ] == str [ 1 ] ) count *= 1 ; else count *= 2 ; for ( int j = 1 ; j < len - 1 ; j ++ ) { if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ; else if ( str [ j ] == str [ j - 1 ] str [ j ] == str [ j + 1 ] str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ; else count *= 3 ; } if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ; else count *= 2 ; return count ; } int main ( ) { char str [ ] = " abc " ; int len = strlen ( str ) ; cout << countWords ( str , len ) << endl ; return 0 ; }

Index/key variables: j
Accumulator variables: count, j, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int replaceDig ( int x , int from , int to ) { int result = 0 ; int multiply = 1 ; while ( x > 0 ) { int reminder = x % 10 ; if ( reminder == from ) result = result + to * multiply ; else result = result + reminder * multiply ; multiply *= 10 ; x = x / 10 ; } return result ; } void calculateMinMaxSum ( int x1 , int x2 ) { int minSum = replaceDig ( x1 , 6 , 5 ) + replaceDig ( x2 , 6 , 5 ) ; int maxSum = replaceDig ( x1 , 5 , 6 ) + replaceDig ( x2 , 5 , 6 ) ; cout << " Minimum ▁ sum ▁ = ▁ " << minSum ; cout << " nMaximum ▁ sum ▁ = ▁ " << maxSum ; } int main ( ) { int x1 = 5466 , x2 = 4555 ; calculateMinMaxSum ( x1 , x2 ) ; return 0 ; }

Accumulator variables: multiply, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void qType1 ( int l , int x , char str [ ] ) { str [ l - 1 ] = x ; } void qType2 ( int l , int r , char str [ ] ) { int freq [ 27 ] = { 0 } ; for ( int i = l - 1 ; i <= r - 1 ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; int count = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) if ( freq [ j ] % 2 ) count ++ ; ( count <= 1 ) ? ( cout << " Yes " << endl ) : ( cout << " No " << endl ) ; } int main ( ) { char str [ ] = " geeksforgeeks " ; int n = strlen ( str ) ; qType1 ( 4 , ' g ' , str ) ; qType2 ( 1 , 4 , str ) ; qType2 ( 2 , 3 , str ) ; qType1 ( 10 , ' t ' , str ) ; qType2 ( 10 , 11 , str ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
#define max  1000
using namespace std ; int getFrequency ( int tree [ max ] [ 27 ] , int idx , int i ) { int sum = 0 ; while ( idx > 0 ) { sum += tree [ idx ] [ i ] ; idx -= ( idx & - idx ) ; } return sum ; } void update ( int tree [ max ] [ 27 ] , int idx , int val , int i ) { while ( idx <= max ) { tree [ idx ] [ i ] += val ; idx += ( idx & - idx ) ; } } void qType1 ( int tree [ max ] [ 27 ] , int l , int x , char str [ ] ) { update ( tree , l , -1 , str [ l - 1 ] - 97 + 1 ) ; str [ l - 1 ] = x ; update ( tree , l , 1 , str [ l - 1 ] - 97 + 1 ) ; } void qType2 ( int tree [ max ] [ 27 ] , int l , int r , char str [ ] ) { int count = 0 ; for ( int i = 1 ; i <= 26 ; i ++ ) { if ( l == 1 ) { if ( getFrequency ( tree , r , i ) % 2 == 1 ) count ++ ; } else { if ( ( getFrequency ( tree , r , i ) - getFrequency ( tree , l - 1 , i ) ) % 2 == 1 ) count ++ ; } } ( count <= 1 ) ? ( cout << " Yes " << endl ) : ( cout << " No " << endl ) ; } void buildBIT ( int tree [ max ] [ 27 ] , char str [ ] , int n ) { memset ( tree , 0 , sizeof ( tree ) ) ; for ( int i = 0 ; i < n ; i ++ ) update ( tree , i + 1 , 1 , str [ i ] - 97 + 1 ) ; } int main ( ) { char str [ ] = " geeksforgeeks " ; int n = strlen ( str ) ; int tree [ max ] [ 27 ] ; buildBIT ( tree , str , n ) ; qType1 ( tree , 4 , ' g ' , str ) ; qType2 ( tree , 1 , 4 , str ) ; qType2 ( tree , 2 , 3 , str ) ; qType1 ( tree , 10 , ' t ' , str ) ; qType2 ( tree , 10 , 11 , str ) ; return 0 ; }

Index/key variables: i, idx, max
Accumulator variables: count, i, idx, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findDivision ( string & str , int a , int b ) { int len = str . length ( ) ; vector < int > lr ( len + 1 , 0 ) ; lr [ 0 ] = ( str [ 0 ] - '0' ) % a ; for ( int i = 1 ; i < len ; i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ; vector < int > rl ( len + 1 , 0 ) ; rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ; int power10 = 10 ; for ( int i = len - 2 ; i >= 0 ; i -- ) { rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ; power10 = ( power10 * 10 ) % b ; } for ( int i = 0 ; i < len - 1 ; i ++ ) { if ( lr [ i ] != 0 ) continue ; if ( rl [ i + 1 ] == 0 ) { cout << " YES STRNEWLINE " ; for ( int k = 0 ; k <= i ; k ++ ) cout << str [ k ] ; cout << " , ▁ " ; for ( int k = i + 1 ; k < len ; k ++ ) cout << str [ k ] ; return ; } } cout << " NO STRNEWLINE " ; } int main ( ) { string str = "123" ; int a = 12 , b = 3 ; findDivision ( str , a , b ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: i, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findTwoscomplement ( string str ) { int n = str . length ( ) ; int i ; for ( i = n - 1 ; i >= 0 ; i -- ) if ( str [ i ] == '1' ) break ; if ( i == -1 ) return '1' + str ; for ( int k = i - 1 ; k >= 0 ; k -- ) { if ( str [ k ] == '1' ) str [ k ] = '0' ; else str [ k ] = '1' ; } return str ; ; } int main ( ) { string str = "00000101" ; cout << findTwoscomplement ( str ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: i, k, stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isequal ( string str ) { int n = str . length ( ) ; int num = 0 , x = 1 , i = n - 1 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( '0' <= str [ i ] && str [ i ] <= '9' ) { num = ( str [ i ] - '0' ) * x + num ; x = x * 10 ; if ( num >= n ) return false ; } else break ; } return num == i + 1 ; } int main ( ) { string str = " geeksforgeeks13" ; isequal ( str ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool kAnagrams ( string str1 , string str2 , int k ) { int flag = 0 ; if ( str1 . length ( ) != str2 . length ( ) ) return false ; int n = str1 . length ( ) ; char arr1 [ n ] ; char arr2 [ n ] ; strcpy ( arr1 , str1 . c_str ( ) ) ; strcpy ( arr2 , str2 . c_str ( ) ) ; sort ( arr1 , arr1 + n ) ; sort ( arr2 , arr2 + n ) ; vector < char > list ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { if ( arr1 [ i ] != arr2 [ i ] ) { list . push_back ( arr2 [ i ] ) ; } } if ( list . size ( ) <= k ) flag = 1 ; if ( flag == 1 ) return true ; else return false ; } int main ( ) { string str1 = " anagram " , str2 = " grammar " ; int k = 3 ; kAnagrams ( str1 , str2 , k ) ; if ( kAnagrams ( str1 , str2 , k ) == true ) cout << " Yes " ; else cout << " No " ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countToMake0lternate ( const string & s ) { int result = 0 ; for ( int i = 0 ; i < ( s . length ( ) - 1 ) ; i ++ ) if ( s [ i ] == s [ i + 1 ] ) return result ; } int main ( ) { cout << countToMake0lternate ( "000111" ) << endl ; cout << countToMake0lternate ( "11111" ) << endl ; cout << countToMake0lternate ( "01010101" ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkString ( string str , long k ) { int n = str . length ( ) ; if ( n % k != 0 ) return false ; unordered_map < string , int > mp ; for ( int i = 0 ; i < n ; i += k ) mp [ str . substr ( i , k ) ] ++ ; if ( mp . size ( ) == 1 ) return true ; if ( mp . size ( ) != 2 ) return false ; if ( ( mp . begin ( ) -> second == ( n / k - 1 ) ) || mp . begin ( ) -> second == 1 ) return true ; return false ; } int main ( ) { checkString ( " abababcd " , 2 ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
# include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; void printGrouped ( string str ) { int n = str . length ( ) ; int count [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { while ( count [ str [ i ] - ' a ' ] -- ) cout << str [ i ] ; count [ str [ i ] - ' a ' ] = 0 ; } } int main ( ) { string str = " geeksforgeeks " ; printGrouped ( 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 ; const int MAX_CHAR = 26 ; void sortByPattern ( string & str , string pat ) { int count [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) count [ str [ i ] - ' a ' ] ++ ; int index = 0 ; for ( int i = 0 ; i < pat . length ( ) ; i ++ ) for ( int j = 0 ; j < count [ pat [ i ] - ' a ' ] ; j ++ ) str [ index ++ ] = pat [ i ] ; } int main ( ) { string pat = " bca " ; string str = " abc " ; sortByPattern ( str , pat ) ; cout << str ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, index, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPossiblePalindrome ( string str ) { int n = str . length ( ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( str [ i ] != ' . ' && str [ n - i - 1 ] != ' . ' && str [ i ] != str [ n - i - 1 ] ) return false ; } return true ; } string smallestPalindrome ( string str ) { if ( ! isPossiblePalindrome ( str ) ) return " Not ▁ Possible " ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' . ' ) { if ( str [ n - i - 1 ] != ' . ' ) str [ i ] = str [ n - i - 1 ] ; else str [ i ] = str [ n - i - 1 ] = ' a ' ; } } return str ; } int main ( ) { string str = " ab . . e . c . a " ; cout << smallestPalindrome ( str ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char flip ( char ch ) { return ( ch == '0' ) ? '1' : '0' ; } int getFlipWithStartingCharcter ( string str , char expected ) { int flipCount = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] != expected ) flipCount ++ ; expected = flip ( expected ) ; } return flipCount ; } int minFlipToMakeStringAlternate ( string str ) { return min ( getFlipWithStartingCharcter ( str , '0' ) , getFlipWithStartingCharcter ( str , '1' ) ) ; } int main ( ) { string str = "0001010111" ; cout << minFlipToMakeStringAlternate ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: flipCount, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int remainderWith7 ( string num ) { int series [ ] = { 1 , 3 , 2 , -1 , -3 , -2 } ; int series_index = 0 ; for ( int i = num . size ( ) - 1 ; i >= 0 ; i -- ) { int digit = num [ i ] - '0' ; result += digit * series [ series_index ] ; series_index = ( series_index + 1 ) % 6 ; result %= 7 ; } if ( result < 0 ) result = ( result + 7 ) % 7 ; return result ; } int main ( ) { string str = "12345" ; cout << " Remainder ▁ with ▁ 7 ▁ is ▁ " << remainderWith7 ( str ) ; return 0 ; }

Index/key variables: i, series_index
Accumulator variables: i, result
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canBecomeEmpty ( string str , string sub_str ) { while ( str . size ( ) > 0 ) { int idx = str . find ( sub_str ) ; if ( idx == -1 ) break ; str . erase ( idx , sub_str . size ( ) ) ; } return ( str . size ( ) == 0 ) ; } int main ( ) { string str = " GEEGEEKSKS " , sub_str = " GEEKS " ; if ( canBecomeEmpty ( str , sub_str ) ) cout << " Yes " else cout << " No " return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isReversible ( string str ) { int i = 0 , j = str . length ( ) - 1 ; while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } int main ( ) { string str = " aba " ; if ( isReversible ( str ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }

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