dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; bool distributingBalls ( int k , int n , string str ) { int a [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { a [ str [ i ] - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( a [ i ] > k ) return false ; return true ; } int main ( ) { long long int n = 6 , k = 3 ; string str = " aacaab " ; if ( distributingBalls ( k , n , str ) ) 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 ; bool isVowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } void FindSubstring ( string str ) { int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( isVowel ( str [ j ] ) == false ) break ; hash . insert ( str [ j ] ) ; if ( hash . size ( ) == 5 ) cout << str . substr ( i , j - i + 1 ) << " ▁ " ; } hash . clear ( ) ; } } int main ( ) { string str = " aeoibsddaeiouudb " ; FindSubstring ( str ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( vector < string > list , string s ) { int n = ( int ) list . size ( ) ; if ( n == 0 ) return false ; for ( int i = 0 ; i < n ; i ++ ) { if ( list [ i ] . size ( ) != s . size ( ) ) continue ; bool diff = false ; for ( int j = 0 ; j < ( int ) list [ i ] . size ( ) ; j ++ ) { if ( list [ i ] [ j ] != s [ j ] ) { if ( ! diff ) diff = true ; else { diff = false ; break ; } } } if ( diff ) return true ; } return false ; } int main ( ) { vector < string > s ; s . push_back ( " bana " ) ; s . push_back ( " apple " ) ; s . push_back ( " banacb " ) ; s . push_back ( " bonanza " ) ; s . push_back ( " banamf " ) ; cout << check ( s , " banana " ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: diff
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sentencePalindrome ( string str ) { int l = 0 , h = str . length ( ) - 1 ; for ( int i = 0 ; i <= h ; i ++ ) str [ i ] = tolower ( str [ i ] ) ; while ( l <= h ) { if ( ! ( str [ l ] >= ' a ' && str [ l ] <= ' z ' ) ) l ++ ; else if ( ! ( str [ h ] >= ' a ' && str [ h ] <= ' z ' ) ) h -- ; else if ( str [ l ] == str [ h ] ) l ++ , h -- ; else return false ; } return true ; } int main ( ) { string str = " Too ▁ hot ▁ to ▁ hoot . " ; if ( sentencePalindrome ( str ) ) cout << " Sentence ▁ is ▁ palindrome . " ; else cout << " Sentence ▁ is ▁ not ▁ palindrome . " ; return 0 ; }

Index/key variables: h, i, l
Accumulator variables: h, i, l, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int xorZero ( string str ) { int one_count = 0 , zero_count = 0 ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( str [ i ] == '1' ) one_count ++ ; else zero_count ++ ; if ( one_count % 2 == 0 ) return zero_count ; return one_count ; } int main ( ) { string str = "11111" ; cout << xorZero ( str ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, one_count, stdc, zero_count
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string encoder ( string key ) { string encoded = " " ; bool arr [ 26 ] = { 0 } ; for ( int i = 0 ; i < key . size ( ) ; i ++ ) { if ( key [ i ] >= ' A ' && key [ i ] <= ' Z ' ) { if ( arr [ key [ i ] - 65 ] == 0 ) { encoded += key [ i ] ; arr [ key [ i ] - 65 ] = 1 ; } } else if ( key [ i ] >= ' a ' && key [ i ] <= ' z ' ) { if ( arr [ key [ i ] - 97 ] == 0 ) { encoded += key [ i ] - 32 ; arr [ key [ i ] - 97 ] = 1 ; } } } for ( int i = 0 ; i < 26 ; i ++ ) { if ( arr [ i ] == 0 ) { arr [ i ] = 1 ; encoded += char ( i + 65 ) ; } } return encoded ; } string cipheredIt ( string msg , string encoded ) { string cipher = " " ; for ( int i = 0 ; i < msg . size ( ) ; i ++ ) { if ( msg [ i ] >= ' a ' && msg [ i ] <= ' z ' ) { int pos = msg [ i ] - 97 ; cipher += encoded [ pos ] ; } else if ( msg [ i ] >= ' A ' && msg [ i ] <= ' Z ' ) { int pos = msg [ i ] - 65 ; cipher += encoded [ pos ] ; } else { cipher += msg [ i ] ; } } return cipher ; } int main ( ) { string key ; key = " Computer " ; cout << " Keyword ▁ : ▁ " << key << endl ; string encoded = encoder ( key ) ; string message = " GeeksforGeeks " ; cout << " Message ▁ before ▁ Ciphering ▁ : ▁ " << message << endl ; cout << " Ciphered ▁ Text ▁ : ▁ " << cipheredIt ( message , encoded ) << endl ; return 0 ; }

Index/key variables: i, pos
Accumulator variables: cipher, encoded, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; bool checkCorrectOrNot ( string s ) { int count [ MAX_CHAR ] = { 0 } ; int n = s . length ( ) ; if ( n == 1 ) return true ; for ( int i = 0 , j = n - 1 ; i < j ; i ++ , j -- ) { count [ s [ i ] - ' a ' ] ++ ; count [ s [ j ] - ' a ' ] -- ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( count [ i ] != 0 ) return false ; return true ; } int main ( ) { string s = " abab " ; if ( checkCorrectOrNot ( s ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; return 0 ; }

Index/key variables: MAX_CHAR, i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkString ( string s ) { int len = s . length ( ) ; int first = s . size ( ) + 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( s [ i ] == '1' ) { first = i ; break ; } } int last = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == '1' ) { last = i ; break ; } } for ( int i = first ; i <= last ; i ++ ) if ( s [ i ] == '0' ) return false ; return true ; } int main ( ) { string s = "00011111111100000" ; checkString ( s ) ? cout << " VALID STRNEWLINE " : cout << " NOT ▁ VALID STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printAllSubstrings ( string s , int n ) { for ( int i = 0 ; i < n ; i ++ ) { char temp [ n - i + 1 ] ; int tempindex = 0 ; for ( int j = i ; j < n ; j ++ ) { temp [ tempindex ++ ] = s [ j ] ; temp [ tempindex ] = ' \0' ; printf ( " % s STRNEWLINE " , temp ) ; } } } int main ( ) { string s = " Geeky " ; printAllSubstrings ( s , s . length ( ) ) ; return 0 ; }

Index/key variables: j, tempindex
Accumulator variables: i, j, stdc, tempindex
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void preserveSpace ( string & str ) { int n = str . length ( ) ; int start = 0 ; int end = n - 1 ; while ( start < end ) { if ( str [ start ] == ' ▁ ' ) { start ++ ; continue ; } else if ( str [ end ] == ' ▁ ' ) { end -- ; continue ; } else { swap ( str [ start ] , str [ end ] ) ; start ++ ; end -- ; } } } int main ( ) { string str = " internship ▁ at ▁ geeks ▁ for ▁ geeks " ; preserveSpace ( str ) ; cout << str ; return 0 ; }

Index/key variables: end, start
Accumulator variables: end, start
C++ program:
#include <iostream>
using namespace std ; void amendSentence ( string str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { str [ i ] = str [ i ] + 32 ; if ( i != 0 ) cout << " ▁ " ; cout << str [ i ] ; } else cout << str [ i ] ; } } int main ( ) { string str = " BruceWayneIsBatman " ; amendSentence ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#include <string>
using namespace std ; string repeat ( string s , int n ) { string s1 = s ; for ( int i = 1 ; i < n ; i ++ ) return s ; } int main ( ) { string s = " geeks " ; int n = 3 ; cout << repeat ( s , n ) << endl ; ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; int factorial ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } int countDistinctPermutations ( string str ) { int length = str . length ( ) ; int freq [ MAX_CHAR ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < length ; i ++ ) if ( str [ i ] >= ' a ' ) freq [ str [ i ] - ' a ' ] ++ ; int fact = 1 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) fact = fact * factorial ( freq [ i ] ) ; return factorial ( length ) / fact ; } int main ( ) { string str = " fvvfhvgv " ; printf ( " % d " , countDistinctPermutations ( 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 uniqueCharacters ( string str ) { int checker = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int bitAtIndex = str [ i ] - ' a ' ; if ( ( checker & ( 1 << bitAtIndex ) ) > 0 ) { return false ; } checker = checker | ( 1 << bitAtIndex ) ; } return true ; } int main ( ) { string str = " geeksforgeeks " ; if ( uniqueCharacters ( str ) ) { cout << " The ▁ String ▁ " << str << " ▁ has ▁ all ▁ unique ▁ characters STRNEWLINE " ; } else { cout << " The ▁ String ▁ " << str << " ▁ has ▁ duplicate ▁ characters STRNEWLINE " ; } return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return true ; return false ; } string createAltStr ( string str1 , string str2 , int start , int l ) { string finalStr = " " ; for ( int i = 0 , j = start ; j < l ; i ++ , j ++ ) finalStr = ( finalStr + str1 . at ( i ) ) + str2 . at ( j ) ; return finalStr ; } string findAltStr ( string str ) { int nv = 0 , nc = 0 ; string vstr = " " , cstr = " " ; int l = str . size ( ) ; for ( int i = 0 ; i < l ; i ++ ) { char ch = str . at ( i ) ; if ( isVowel ( ch ) ) { nv ++ ; vstr = vstr + ch ; } else { nc ++ ; cstr = cstr + ch ; } } if ( abs ( nv - nc ) >= 2 ) return " no ▁ such ▁ string " ; if ( nv > nc ) return ( vstr . at ( 0 ) + createAltStr ( cstr , vstr , 1 , nv ) ) ; if ( nc > nv ) return ( cstr . at ( 0 ) + createAltStr ( vstr , cstr , 1 , nc ) ) ; if ( cstr . at ( 0 ) < vstr . at ( 0 ) ) return createAltStr ( cstr , vstr , 0 , nv ) ; return createAltStr ( vstr , cstr , 0 , nc ) ; } int main ( ) { string str = " geeks " ; cout << findAltStr ( str ) ; return 0 ; }

Accumulator variables: i, j, nc, nv, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { string str = " geeksforgeeks " ; reverse ( str . begin ( ) , str . end ( ) ) ; cout << str ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalRec ( char str [ ] , int s , int e ) { if ( s == e ) return true ; if ( str [ s ] != str [ e ] ) return false ; if ( s < e + 1 ) return isPalRec ( str , s + 1 , e - 1 ) ; return true ; } bool isPalindrome ( char str [ ] ) { int n = strlen ( str ) ; if ( n == 0 ) return true ; return isPalRec ( str , 0 , n - 1 ) ; } int main ( ) { char str [ ] = " geeg " ; if ( isPalindrome ( str ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: e, s
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; int countSubstringWithEqualEnds ( string s ) { int result = 0 ; int n = s . length ( ) ; int count [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count [ s [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ; return result ; } int main ( ) { string s ( " abcab " ) ; cout << countSubstringWithEqualEnds ( s ) ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char maxRepeating ( string str ) { int n = str . length ( ) ; int count = 0 ; char res = str [ 0 ] ; int cur_count = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ; else { if ( cur_count > count ) { count = cur_count ; res = str [ i ] ; } cur_count = 1 ; } } return res ; } int main ( ) { string str = " aaaabbaaccde " ; cout << maxRepeating ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cur_count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define MAX  10000
#define CHAR_SIZE  26
using namespace std ; void precompute ( int mat [ MAX ] [ CHAR_SIZE ] , char str [ ] , int len ) { for ( int i = 0 ; i < CHAR_SIZE ; ++ i ) mat [ len ] [ i ] = len ; for ( int i = len - 1 ; i >= 0 ; -- i ) { for ( int j = 0 ; j < CHAR_SIZE ; ++ j ) mat [ i ] [ j ] = mat [ i + 1 ] [ j ] ; mat [ i ] [ str [ i ] - ' a ' ] = i ; } } bool query ( int mat [ MAX ] [ CHAR_SIZE ] , const char * str , int len ) { int pos = 0 ; for ( int i = 0 ; i < strlen ( str ) ; ++ i ) { if ( mat [ pos ] [ str [ i ] - ' a ' ] >= len ) return false ; else pos = mat [ pos ] [ str [ i ] - ' a ' ] + 1 ; } return true ; } int main ( ) { char S [ ] = " geeksforgeeks " ; int len = strlen ( S ) ; int mat [ MAX ] [ CHAR_SIZE ] ; precompute ( mat , S , len ) ; query ( mat , " gg " , len ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; query ( mat , " gro " , len ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; query ( mat , " gfg " , len ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; query ( mat , " orf " , len ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; return 0 ; }

Index/key variables: CHAR_SIZE, MAX, i, j, len, pos
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void query ( char s [ ] , int i , int j ) { int n = strlen ( s ) ; i %= n ; j %= n ; ( s [ i ] == s [ j ] ) ? ( cout << " Yes " << endl ) : ( cout << " No " << endl ) ; } int main ( ) { char X [ ] = " geeksforgeeks " ; query ( X , 0 , 8 ) ; query ( X , 8 , 13 ) ; query ( X , 6 , 15 ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairs ( string str ) { int result = 0 ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ; return result ; } int main ( ) { string str = " geeksforgeeks " ; cout << countPairs ( str ) ; 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 ; void longestString ( string str1 , string str2 ) { int count1 [ 26 ] = { 0 } , count2 [ 26 ] = { 0 } ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) count1 [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < str2 . length ( ) ; i ++ ) count2 [ str2 [ i ] - ' a ' ] ++ ; string result ; for ( int i = 0 ; i < 26 ; i ++ ) for ( int j = 1 ; j <= min ( count1 [ i ] , count2 [ i ] ) ; j ++ ) result . push_back ( ' a ' + i ) ; cout << result ; } int main ( ) { string str1 = " geeks " , str2 = " cake " ; longestString ( str1 , str2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; bool checkPattern ( string str , string pattern ) { int len = pattern . length ( ) ; if ( str . length ( ) < len ) return false ; for ( int i = 0 ; i < len - 1 ; i ++ ) { char x = pattern [ i ] ; char y = pattern [ i + 1 ] ; size_t last = str . find_last_of ( x ) ; size_t first = str . find_first_of ( y ) ; if ( last == string :: npos first == string :: npos last > first ) return false ; } return true ; } int main ( ) { string str = " engineers ▁ rock " ; string pattern = " gsr " ; cout << boolalpha << checkPattern ( str , pattern ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findSum ( string str ) { string temp = " " ; int sum = 0 ; for ( char ch : str ) { if ( isdigit ( ch ) ) temp += ch ; else { sum += atoi ( temp . c_str ( ) ) ; temp = " " ; } } return sum + atoi ( temp . c_str ( ) ) ; } int main ( ) { string str = "12abc20yz68" ; cout << findSum ( str ) ; return 0 ; }

Accumulator variables: sum, temp
Iterator variables: ch
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countkDist ( string str , int k ) { int n = str . length ( ) ; int res = 0 ; int cnt [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int dist_count = 0 ; memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( int j = i ; j < n ; j ++ ) { if ( cnt [ str [ j ] - ' a ' ] == 0 ) dist_count ++ ; cnt [ str [ j ] - ' a ' ] ++ ; if ( dist_count == k ) res ++ ; if ( dist_count > k ) break ; } } return res ; } int main ( ) { string str = " abcbaa " ; int k = 3 ; cout << " Total ▁ substrings ▁ with ▁ exactly ▁ " << k << " ▁ distinct ▁ characters ▁ : " << countkDist ( str , k ) << endl ; return 0 ; }

Index/key variables: j
Accumulator variables: dist_count, i, j, res, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; string to_upper ( string & in ) { for ( int i = 0 ; i < in . length ( ) ; i ++ ) if ( ' a ' <= in [ i ] <= ' z ' ) in [ i ] = in [ i ] - ' a ' + ' A ' ; return in ; } int main ( ) { string str = " geeksforgeeks " ; cout << to_upper ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinLength ( string arr [ ] , int n ) { int min = arr [ 0 ] . length ( ) ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] . length ( ) < min ) min = arr [ i ] . length ( ) ; return ( min ) ; } string commonPrefix ( string arr [ ] , int n ) { int minlen = findMinLength ( arr , n ) ; string result ; for ( int i = 0 ; i < minlen ; i ++ ) { current = arr [ 0 ] [ i ] ; for ( int j = 1 ; j < n ; j ++ ) if ( arr [ j ] [ i ] != current ) return result ; result . push_back ( current ) ; } return ( result ) ; } int main ( ) { string arr [ ] = { " geeksforgeeks " , " geeks " , " geek " , " geezer " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; string ans = commonPrefix ( arr , n ) ; if ( ans . length ( ) ) cout << " The ▁ longest ▁ common ▁ prefix ▁ is ▁ " << ans ; else cout << " There ▁ is ▁ no ▁ common ▁ prefix " ; 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 ; void printZigZagConcat ( string str , int n ) { if ( n == 1 ) { cout << str ; return ; } int len = str . length ( ) ; string arr [ n ] ; int row = 0 ; bool down ; for ( int i = 0 ; i < len ; ++ i ) { arr [ row ] . push_back ( str [ i ] ) ; if ( row == n - 1 ) down = false ; else if ( row == 0 ) down = true ; ( down ) ? ( row ++ ) : ( row -- ) ; } for ( int i = 0 ; i < n ; ++ i ) cout << arr [ i ] ; } int main ( ) { string str = " GEEKSFORGEEKS " ; int n = 3 ; printZigZagConcat ( str , n ) ; return 0 ; }

Index/key variables: i, n, row
Accumulator variables: row, stdc
Iterator variables: i
Boolean variables: down
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalin ( char str [ ] , int st , int end ) { while ( st < end ) { if ( str [ st ] != str [ end ] ) return false ; st ++ ; end -- ; } return true ; } int findMinInsert ( char str [ ] , int n ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( isPalin ( str , 0 , i ) ) return ( n - i - 1 ) ; } } int main ( ) { char Input [ ] = " JAVA " ; printf ( " % d " , findMinInsert ( Input , strlen ( Input ) ) ) ; return 0 ; }

Index/key variables: end, st
Accumulator variables: end, i, st, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; long int removeRecur ( long int n ) { int prev_digit = n % 10 ; long int pow = 10 ; long int res = prev_digit ; while ( n ) { int curr_digit = n % 10 ; if ( curr_digit != prev_digit ) { res += curr_digit * pow ; prev_digit = curr_digit ; pow *= 10 ; } n = n / 10 ; } return res ; } int main ( ) { long int n = 12224 ; cout << removeRecur ( n ) ; return 0 ; }

Accumulator variables: pow, res
C++ program:
#include <bits/stdc++.h>
using namespace std ; void stringFilter ( char * str ) { int n = strlen ( str ) ; int i = -1 ; int j = 0 ; while ( j < n ) { if ( j < n - 1 && str [ j ] == ' a ' && str [ j + 1 ] == ' c ' ) j += 2 ; else if ( str [ j ] == ' b ' ) j ++ ; else if ( i >= 0 && str [ j ] == ' c ' && str [ i ] == ' a ' ) i -- , j ++ ; else str [ ++ i ] = str [ j ++ ] ; } str [ ++ i ] = ' \0' ; } int main ( ) { char str1 [ ] = " ad " ; cout << " Input ▁ = > ▁ " << str1 << " Output = > " stringFilter ( str1 ) ; cout << str1 << endl << endl ; char str2 [ ] = " acbac " ; cout << " Input ▁ = > ▁ " << str2 << " Output = > " stringFilter ( str2 ) ; cout << str2 << endl << endl ; char str3 [ ] = " aaac " ; cout << " Input ▁ = > ▁ " << str3 << " Output = > " stringFilter ( str3 ) ; cout << str3 << endl << endl ; char str4 [ ] = " react " ; cout << " Input ▁ = > ▁ " << str4 << " Output = > " stringFilter ( str4 ) ; cout << str4 << endl << endl ; char str5 [ ] = " aa " ; cout << " Input ▁ = > ▁ " << str5 << " Output = > " stringFilter ( str5 ) ; cout << str5 << endl << endl ; char str6 [ ] = " ababaac " ; cout << " Input ▁ = > ▁ " << str6 << " Output = > " stringFilter ( str6 ) ; cout << str6 << endl << endl ; char str [ ] = " abc " ; cout << " Input ▁ = > ▁ " << str << " Output = > " stringFilter ( str ) ; cout << str << endl << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int myAtoi ( const char * str ) { int sign = 1 , base = 0 , i = 0 ; while ( str [ i ] == ' ▁ ' ) { i ++ ; } if ( str [ i ] == ' - ' str [ i ] == ' + ' ) { sign = 1 - 2 * ( str [ i ++ ] == ' - ' ) ; } while ( str [ i ] >= '0' && str [ i ] <= '9' ) { if ( base > INT_MAX / 10 || ( base == INT_MAX / 10 && str [ i ] - '0' > 7 ) ) { if ( sign == 1 ) return INT_MAX ; else return INT_MIN ; } base = 10 * base + ( str [ i ++ ] - '0' ) ; } return base * sign ; } int main ( ) { char str [ ] = " ▁ - 123" ; int val = myAtoi ( str ) ; cout << " ▁ " << val ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define NO_OF_CHARS  256
bool areAnagram ( char * str1 , char * str2 ) { int count [ NO_OF_CHARS ] = { 0 } ; int i ; for ( i = 0 ; str1 [ i ] && str2 [ i ] ; i ++ ) { count [ str1 [ i ] ] ++ ; count [ str2 [ i ] ] -- ; } if ( str1 [ i ] str2 [ i ] ) return false ; for ( i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( count [ i ] ) return false ; return true ; } int main ( ) { char str1 [ ] = " geeksforgeeks " ; char str2 [ ] = " forgeeksgeeks " ; if ( areAnagram ( str1 , str2 ) ) cout << " The ▁ two ▁ strings ▁ are ▁ anagram ▁ of ▁ each ▁ other " ; else cout << " The ▁ two ▁ strings ▁ are ▁ not ▁ anagram ▁ of ▁ each ▁ " " other " ; return 0 ; }

Index/key variables: NO_OF_CHARS, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
# include <iostream>
# include <climits>
using namespace std ; int firstNonRepeating ( string str ) { int fi [ 256 ] ; for ( int i = 0 ; i < 256 ; i ++ ) fi [ i ] = -1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( fi [ str [ i ] ] == -1 ) { fi [ str [ i ] ] = i ; } else { fi [ str [ i ] ] = -2 ; } } int res = INT_MAX ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( fi [ i ] >= 0 ) res = min ( res , fi [ i ] ) ; } if ( res == INT_MAX ) return -1 ; else return res ; } int main ( ) { string str ; str = " geeksforgeeks " ; int firstIndex = firstNonRepeating ( str ) ; if ( firstIndex == -1 ) cout << " Either ▁ all ▁ characters ▁ are ▁ repeating ▁ or ▁ string ▁ is ▁ empty " ; else cout << " First ▁ non - repeating ▁ character ▁ is ▁ " << str [ firstIndex ] ; return 0 ; }

Index/key variables: firstIndex, i
Accumulator variables: i
Iterator variables: i