dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MAX = 256 ; int freq [ 256 ] [ 1000 ] = { 0 } ; void preCalculate ( string str , int n ) { freq [ ( int ) str [ 0 ] ] [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { char ch = str [ i ] ; for ( int j = 0 ; j < MAX ; j ++ ) { char charToUpdate = ( char ) j ; if ( charToUpdate == ch ) freq [ j ] [ i ] = freq [ j ] [ i - 1 ] + 1 ; else freq [ j ] [ i ] = freq [ j ] [ i - 1 ] ; } } } int getFrequency ( char ch , int l , int r ) { if ( l == 0 ) return freq [ ( int ) ch ] [ r ] ; else return ( freq [ ( int ) ch ] [ r ] - freq [ ( int ) ch ] [ l - 1 ] ) ; } string getString ( char x ) { string s ( 1 , x ) ; return s ; } string lastNonRepeating ( string str , int n , int l , int r ) { for ( int i = r ; i >= l ; i -- ) { char ch = str [ i ] ; if ( getFrequency ( ch , l , r ) == 1 ) return getString ( ch ) ; } return " - 1" ; } int main ( ) { string str = " GeeksForGeeks " ; int n = str . length ( ) ; int queries [ 3 ] [ 2 ] = { { 2 , 9 } , { 2 , 3 } , { 0 , 12 } } ; int q = 3 ; preCalculate ( str , n ) ; for ( int i = 0 ; i < q ; i ++ ) { cout << ( lastNonRepeating ( str , n , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) << endl ; ; } }

Index/key variables: i, j, r
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void pre_process ( vector < string > & substrings , string s ) { int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { string dup = " " ; for ( int j = i ; j < n ; j ++ ) { dup += s [ j ] ; substrings . push_back ( dup ) ; } } sort ( substrings . begin ( ) , substrings . end ( ) ) ; } int main ( ) { string s = " geek " ; vector < string > substrings ; pre_process ( substrings , s ) ; int queries [ ] = { 1 , 5 , 10 } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) cout << substrings [ queries [ i ] - 1 ] << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: dup, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Priority { string s ; int count ; } ; struct Compare { int operator() ( Priority a , Priority b ) { if ( a . count > b . count ) return 1 ; else if ( a . count < b . count ) return -1 ; return 0 ; } } ; static void FindString ( string str [ ] , int num [ ] , int n ) { priority_queue < int , vector < Priority > , Compare > p ; for ( int i = 0 ; i < n ; i ++ ) { Priority x ; x . s = str [ i ] ; x . count = num [ i ] ; p . push ( x ) ; } while ( p . size ( ) > 1 ) { Priority x = p . top ( ) ; p . pop ( ) ; Priority y = p . top ( ) ; p . pop ( ) ; int temp = x . count + y . count ; string sb = x . s + y . s ; Priority z ; z . count = temp ; z . s = sb ; p . push ( z ) ; } Priority z = p . top ( ) ; p . pop ( ) ; cout << z . s << endl ; } int main ( ) { string str [ ] = { " Geeks " , " For " , " Geeks " } ; int num [ ] = { 2 , 3 , 7 } ; int n = sizeof ( num ) / sizeof ( int ) ; FindString ( str , num , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Compare, Priority
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCost ( string str , int K ) { int n = str . length ( ) ; int res = 999999999 , count = 0 , a , b ; int cnt [ 27 ] ; memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( int i = 0 ; i < n ; i ++ ) cnt [ str [ i ] - ' a ' + 1 ] ++ ; for ( int i = 1 ; i < ( 26 - K + 1 ) ; i ++ ) { a = i ; b = i + K ; count = 0 ; for ( int j = 1 ; j <= 26 ; j ++ ) { if ( cnt [ j ] > 0 ) { if ( j >= a && j >= b ) count = count + ( min ( j - b , 25 - j + a + 1 ) ) * cnt [ j ] ; else if ( j <= a && j <= b ) count = count + ( min ( a - j , 25 + j - b + 1 ) ) * cnt [ j ] ; } } res = min ( res , count ) ; } for ( int i = 26 - K + 1 ; i <= 26 ; i ++ ) { a = i ; b = ( i + K ) % 26 ; count = 0 ; for ( int j = 1 ; j <= 26 ; j ++ ) { if ( cnt [ j ] > 0 ) { if ( j >= b and j <= a ) count = count + ( min ( j - b , a - j ) ) * cnt [ j ] ; } } res = min ( res , count ) ; } return res ; } int main ( ) { string str = " abcdefghi " ; int K = 2 ; cout << minCost ( str , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <stdlib.h>
using namespace std ; void printBinStr ( int * str , int len ) { for ( int i = 0 ; i < len ; i ++ ) { cout << str [ i ] ; } cout << endl ; } void generateBinStr ( int * str , int len , int currlen , int occur , int nextbit ) { if ( currlen == len ) { if ( occur == 2 && nextbit == 0 ) printBinStr ( str , len ) ; return ; } if ( currlen == 0 ) { str [ 0 ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } else { if ( occur < 2 ) { str [ currlen ] = nextbit ; if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { occur += 1 ; } generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } else { if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { return ; } else { str [ currlen ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } } } } int main ( ) { int n = 5 ; if ( n < 4 ) cout << -1 ; else { int * str = new int [ n ] ; generateBinStr ( str , n , 0 , 0 , 0 ) ; generateBinStr ( str , n , 0 , 0 , 1 ) ; } return 0 ; }

Index/key variables: currlen, i, n
Accumulator variables: i, occur
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printLastChar ( string str ) { str = str + " ▁ " ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == ' ▁ ' ) cout << str [ i - 1 ] << " ▁ " ; } } int main ( ) { string str = " Geeks ▁ for ▁ Geeks " ; printLastChar ( str ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxBalancedStr ( string s ) { int open1 = 0 , close1 = 0 ; int open2 = 0 , close2 = 0 ; int open3 = 0 , close3 = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s [ i ] ) { case ' ( ' : open1 ++ ; break ; case ' ) ' : close1 ++ ; break ; case ' { ' : open2 ++ ; break ; case ' } ' : close2 ++ ; break ; case ' [ ' : open3 ++ ; break ; case ' ] ' : close3 ++ ; break ; } } int maxLen = 2 * min ( open1 , close1 ) + 2 * min ( open2 , close2 ) + 2 * min ( open3 , close3 ) ; return maxLen ; } int main ( ) { string s = " ) ) [ ] ] ( ( " ; cout << maxBalancedStr ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: close1, close2, close3, i, open1, open2, open3, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string strBitwiseOR ( string * arr , int n ) { string res ; int max_size = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { max_size = max ( max_size , ( int ) arr [ i ] . size ( ) ) ; reverse ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { string s ; for ( int j = 0 ; j < max_size - arr [ i ] . size ( ) ; j ++ ) s += '0' ; arr [ i ] = arr [ i ] + s ; } for ( int i = 0 ; i < max_size ; i ++ ) { int curr_bit = 0 ; for ( int j = 0 ; j < n ; j ++ ) curr_bit = curr_bit | ( arr [ j ] [ i ] - '0' ) ; res += ( curr_bit + '0' ) ; } reverse ( res . begin ( ) , res . end ( ) ) ; return res ; } int main ( ) { string arr [ ] = { "10" , "11" , "1000001" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << strBitwiseOR ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, res, s, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCost ( string s1 , string s2 , int a , int b , int c , int d , int n ) { int cost = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s1 [ i ] == s2 [ i ] ) continue ; else { if ( ( s1 [ i ] == '1' && s2 [ i ] == '2' ) || ( s2 [ i ] == '1' && s1 [ i ] == '2' ) ) cost += min ( d , min ( a , b + c ) ) ; else if ( ( s1 [ i ] == '2' && s2 [ i ] == '3' ) || ( s2 [ i ] == '2' && s1 [ i ] == '3' ) ) cost += min ( d , min ( b , a + c ) ) ; else if ( ( s1 [ i ] == '1' && s2 [ i ] == '3' ) || ( s2 [ i ] == '1' && s1 [ i ] == '3' ) ) cost += min ( d , min ( c , a + b ) ) ; } } return cost ; } int main ( ) { string s1 = "121" ; string s2 = "223" ; int a = 2 , b = 3 , c = 4 , d = 10 ; int n = s1 . size ( ) ; cout << findCost ( s1 , s2 , a , b , c , d , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cost, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int check ( string s , int k ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s [ i ] != s [ i % k ] ) return false ; return true ; } int countCommonDivisors ( string a , string b ) { int ct = 0 ; int n = a . size ( ) , m = b . size ( ) ; for ( int i = 1 ; i <= min ( n , m ) ; i ++ ) { if ( n % i == 0 && m % i == 0 ) if ( a . substr ( 0 , i ) == b . substr ( 0 , i ) ) if ( check ( a , i ) && check ( b , i ) ) ct ++ ; } return ct ; } int main ( ) { string a = " xaxa " , b = " xaxaxaxa " ; cout << countCommonDivisors ( a , b ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ct, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { struct node * left ; int data ; struct node * right ; } ; void levelOrder ( node * root ) { if ( root == NULL ) return ; queue < node * > q ; node * curr ; q . push ( root ) ; q . push ( NULL ) ; while ( q . size ( ) > 1 ) { curr = q . front ( ) ; q . pop ( ) ; if ( curr == NULL ) { q . push ( NULL ) ; cout << " STRNEWLINE " ; } else { if ( curr -> left ) q . push ( curr -> left ) ; if ( curr -> right ) q . push ( curr -> right ) ; cout << curr -> data << " ▁ " ; } } } node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } int main ( ) { node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; levelOrder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nextZero ( int i , int occurrences [ ] ) { while ( i < 26 ) { if ( occurrences [ i ] == 0 ) return i ; i ++ ; } return -1 ; } string getModifiedString ( string str ) { int n = str . length ( ) ; if ( n > 26 ) return " - 1" ; string ch = str ; int i , occurrences [ 26 ] = { 0 } ; for ( i = 0 ; i < n ; i ++ ) occurrences [ ch [ i ] - ' a ' ] ++ ; int index = nextZero ( 0 , occurrences ) ; for ( i = 0 ; i < n ; i ++ ) { if ( occurrences [ ch [ i ] - ' a ' ] > 1 ) { occurrences [ ch [ i ] - ' a ' ] -- ; ch [ i ] = ( char ) ( ' a ' + index ) ; occurrences [ index ] = 1 ; index = nextZero ( index + 1 , occurrences ) ; } } cout << ch << endl ; } int main ( ) { string str = " geeksforgeeks " ; getModifiedString ( str ) ; }

Index/key variables: i, index
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string trim ( const string & s ) { auto start = s . begin ( ) ; while ( start != s . end ( ) && isspace ( * start ) ) start ++ ; auto end = s . end ( ) ; do { end -- ; } while ( distance ( start , end ) > 0 && isspace ( * end ) ) ; return string ( start , end + 1 ) ; } string extractSecretMessage ( string str , string sub ) { size_t pos ; while ( ( pos = str . find ( sub ) ) != string :: npos ) str . replace ( pos , 3 , " ▁ " ) ; str = trim ( str ) ; return str ; } int main ( int argc , char const * argv [ ] ) { string str = " LIELIEILIEAMLIECOOL " ; string sub = " LIE " ; cout << extractSecretMessage ( str , sub ) << endl ; return 0 ; }

Accumulator variables: end, start, stdc
C++ program:
#include <iostream>
#include <string>
using namespace std ; int subStringsStartingHere ( string str , int n , int startIndex ) { int count = 0 , i = 1 ; while ( i <= n ) { if ( str . substr ( 0 , i ) == str . substr ( startIndex , i ) ) { count ++ ; } else break ; i ++ ; } return count ; } int countSubStrings ( string str , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) count += subStringsStartingHere ( str , n , i ) ; } return count ; } int main ( ) { string str = " abcda " ; int n = str . length ( ) ; cout << ( countSubStrings ( str , n ) ) ; }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binarySearch ( string arr [ ] , string x , int n ) { int l = 0 ; int r = n - 1 ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( x == ( arr [ m ] ) ) res = 0 ; if ( res == 0 ) return m ; if ( x > ( arr [ m ] ) ) l = m + 1 ; else r = m - 1 ; } return -1 ; } int main ( ) { string arr [ ] = { " contribute " , " geeks " , " ide " , " practice " } ; string x = " ide " ; int n = 4 ; int result = binarySearch ( arr , x , n ) ; if ( result == -1 ) cout << ( " Element ▁ not ▁ present " ) ; else cout << ( " Element ▁ found ▁ at ▁ index ▁ " ) << result ; }

Index/key variables: m
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define max_val  257
int PrimeCharacters ( string s ) { vector < bool > prime ( max_val + 1 , true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { if ( prime [ int ( s [ i ] ) ] ) count ++ ; } return count ; } int main ( ) { string S = " geeksforgeeks " ; cout << PrimeCharacters ( S ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: count, i, p, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; void getStudentsList ( string file [ ] , int n ) { int avgScore ; int maxAvgScore = INT_MIN ; vector < string > names ; for ( int i = 0 ; i < n ; i += 4 ) { avgScore = ( stoi ( file [ i + 1 ] ) + stoi ( file [ i + 2 ] ) + stoi ( file [ i + 3 ] ) ) / 3 ; if ( avgScore > maxAvgScore ) { maxAvgScore = avgScore ; names . clear ( ) ; names . push_back ( file [ i ] ) ; } else if ( avgScore == maxAvgScore ) names . push_back ( file [ i ] ) ; } for ( int i = 0 ; i < names . size ( ) ; i ++ ) { cout << names [ i ] + " ▁ " ; } cout << maxAvgScore ; } int main ( ) { string file [ ] = { " Shrikanth " , "20" , "30" , "10" , " Ram " , "100" , "50" , "10" } ; int n = sizeof ( file ) / sizeof ( file [ 0 ] ) ; getStudentsList ( file , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ALL_CHARS  256
bool compare ( char * arr1 , char * arr2 ) { for ( int i = 0 ; i < ALL_CHARS ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } bool search ( string pat , string txt ) { int M = pat . length ( ) ; int N = txt . length ( ) ; int i ; char countP [ ALL_CHARS ] = { 0 } ; char countTW [ ALL_CHARS ] = { 0 } ; for ( i = 0 ; i < M ; i ++ ) { ( countP [ pat [ i ] ] ) ++ ; ( countTW [ txt [ i ] ] ) ++ ; } for ( i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) { return true ; } ( countTW [ txt [ i ] ] ) ++ ; countTW [ txt [ i - M ] ] -- ; } if ( compare ( countP , countTW ) ) return true ; return false ; } int calculatesubString ( string s1 , string s2 , int n ) { int count = 0 , j = 0 , x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int len = 1 ; len <= n - i ; len ++ ) { if ( search ( s1 . substr ( i , len ) , s2 ) ) { count = count + 1 ; } } } return count ; } int main ( ) { string str1 = " PLEASEHELPIMTRAPPED " ; string str2 = " INAKICKSTARTFACTORY " ; int len = str1 . length ( ) ; cout << calculatesubString ( str1 , str2 , len ) ; return 0 ; }

Index/key variables: ALL_CHARS, i
Accumulator variables: i, len, stdc
Iterator variables: i, len
C++ program:
#include <bits/stdc++.h>
using namespace std ; int strScore ( string str [ ] , string s , int n ) { int score = 0 , index ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == s ) { for ( int j = 0 ; j < s . length ( ) ; j ++ ) score += s [ j ] - ' a ' + 1 ; index = i + 1 ; break ; } } score = score * index ; return score ; } int main ( ) { string str [ ] = { " sahil " , " shashanak " , " sanjit " , " abhinav " , " mohit " } ; string s = " abhinav " ; int n = sizeof ( str ) / sizeof ( str [ 0 ] ) ; int score = strScore ( str , s , n ) ; cout << score << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, score, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sameCharAdj ( string str ) { int n = str . length ( ) , i ; set < char > st ; st . insert ( str [ 0 ] ) ; for ( i = 1 ; i < n ; i ++ ) { if ( str [ i ] == str [ i - 1 ] ) continue ; if ( st . find ( str [ i ] ) != st . end ( ) ) return false ; st . insert ( str [ i ] ) ; } return true ; } int minSwaps ( string str , int l , int r , int cnt , int minm ) { if ( l == r ) { if ( sameCharAdj ( str ) ) return cnt ; else return INT_MAX ; } for ( int i = l + 1 ; i <= r ; i ++ ) { swap ( str [ i ] , str [ l ] ) ; cnt ++ ; int x = minSwaps ( str , l + 1 , r , cnt , minm ) ; swap ( str [ i ] , str [ l ] ) ; cnt -- ; int y = minSwaps ( str , l + 1 , r , cnt , minm ) ; minm = min ( minm , min ( x , y ) ) ; } return minm ; } int main ( ) { string str = " abbaacb " ; int n = str . length ( ) , cnt = 0 , minm = INT_MAX ; cout << minSwaps ( str , 0 , n - 1 , cnt , minm ) << endl ; return 0 ; }

Index/key variables: i, l
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
int find ( int parent [ ] , int i ) { if ( parent [ i ] == -1 ) return i ; return find ( parent , parent [ i ] ) ; } void Union ( int parent [ ] , int x , int y ) { int xset = find ( parent , x ) ; int yset = find ( parent , y ) ; parent [ xset ] = yset ; }

Index/key variables: i, xset
C++ program:
#include <bits/stdc++.h>
using namespace std ; string K_thletter ( string S , int K ) { int N = S . size ( ) ; long size = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( isdigit ( S [ i ] ) ) size = size * ( S [ i ] - '0' ) ; else size += 1 ; } for ( int i = N - 1 ; i >= 0 ; -- i ) { K %= size ; if ( K == 0 && isalpha ( S [ i ] ) ) return ( string ) " " + S [ i ] ; if ( isdigit ( S [ i ] ) ) size = size / ( S [ i ] - '0' ) ; else size -= 1 ; } } int main ( ) { string S = " geeks2for2" ; int K = 15 ; cout << K_thletter ( S , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: size, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minParentheses ( string p ) { int bal = 0 ; int ans = 0 ; for ( int i = 0 ; i < p . length ( ) ; ++ i ) { bal += p [ i ] == ' ( ' ? 1 : -1 ; if ( bal == -1 ) { ans += 1 ; bal += 1 ; } } return bal + ans ; } int main ( ) { string p = " ( ) ) " ; cout << minParentheses ( p ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, bal, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalindrome ( string r ) { string p = r ; reverse ( p . begin ( ) , p . end ( ) ) ; return ( r == p ) ; } bool CheckStr ( string s ) { int l = s . length ( ) ; int i ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . substr ( 0 , i ) ) ) break ; } if ( i == ( l + 1 ) ) return false ; i = 2 ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . substr ( l - i , i ) ) ) return true ; } return false ; } int main ( ) { string s = " abccbarfgdbd " ; if ( CheckStr ( s ) ) cout << " YES STRNEWLINE " ; else cout << " NO STRNEWLINE " ; return 0 ; }

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

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  256
int minimumOperation ( string s ) { int n = s . length ( ) ; vector < int > first_occ ( MAX , -1 ) ; int res = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { char x = s [ i ] ; if ( first_occ [ x ] == -1 ) first_occ [ x ] = i ; else { int last_occ = ( n - i - 1 ) ; res = min ( res , first_occ [ x ] + last_occ ) ; } } return res ; } int main ( ) { string s = " bacdefghipalop " ; cout << minimumOperation ( s ) << endl ; return 0 ; }

Index/key variables: i, x
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void getSmallestAndLargest ( string s , int k ) { string currStr = s . substr ( 0 , k ) ; string lexMin = currStr ; string lexMax = currStr ; for ( int i = k ; i < s . length ( ) ; i ++ ) { currStr = currStr . substr ( 1 , k ) + s [ i ] ; if ( lexMax < currStr ) lexMax = currStr ; if ( lexMin > currStr ) lexMin = currStr ; } cout << ( lexMin ) << endl ; cout << ( lexMax ) << endl ; } int main ( ) { string str = " GeeksForGeeks " ; int k = 3 ; getSmallestAndLargest ( str , k ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printInitials ( string str ) { int len = str . length ( ) ; str . erase ( 0 , str . find_first_not_of ( ' ▁ ' ) ) ; str . erase ( str . find_last_not_of ( ' ▁ ' ) + 1 ) ; string t = " " ; for ( int i = 0 ; i < len ; i ++ ) { char ch = str [ i ] ; if ( ch != ' ▁ ' ) t = t + ch ; else { cout << ( char ) toupper ( t [ 0 ] ) << " . ▁ " ; t = " " ; } } string temp = " " ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { if ( j == 0 ) temp = temp + ( char ) toupper ( t [ 0 ] ) ; else temp = temp + ( char ) tolower ( t [ j ] ) ; } cout << temp << endl ; } int main ( ) { string str = " ishita ▁ bhuiya " ; printInitials ( str ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findNumberOfTimes ( string str1 , string str2 ) { int freq [ 26 ] = { 0 } ; int freq2 [ 26 ] = { 0 } ; int l1 = str1 . length ( ) ; int l2 = str2 . length ( ) ; for ( int i = 0 ; i < l1 ; i ++ ) freq [ str1 [ i ] - ' a ' ] += 1 ; for ( int i = 0 ; i < l2 ; i ++ ) freq2 [ str2 [ i ] - ' a ' ] += 1 ; int count = INT_MAX ; for ( int i = 0 ; i < l2 ; i ++ ) { if ( freq2 [ str2 [ i ] - ' a ' ] != 0 ) count = min ( count , freq [ str2 [ i ] - ' a ' ] / freq2 [ str2 [ i ] - ' a ' ] ) ; } return count ; } int main ( ) { string str1 = " foreeksgekseg " ; string str2 = " geeks " ; cout << findNumberOfTimes ( str1 , str2 ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool solve ( string s1 , string s2 ) { bool flag1 = 0 , flag2 = 0 ; if ( s1 . length ( ) != s2 . length ( ) ) return false ; int l = s1 . length ( ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( s1 [ i ] == '1' ) flag1 = 1 ; if ( s2 [ i ] == '1' ) flag2 = 1 ; if ( flag1 && flag2 ) return true ; } if ( ! flag1 && ! flag2 ) return true ; return false ; } int main ( ) { string s1 = "100101" ; string s2 = "100000" ; if ( solve ( s1 , s2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char nextGreatestAlphabet ( vector < char > & alphabets , char K ) { int n = alphabets . size ( ) ; if ( K >= alphabets [ n - 1 ] ) return alphabets [ 0 ] ; int l = 0 , r = alphabets . size ( ) - 1 ; int ans = -1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( alphabets [ mid ] > K ) { r = mid - 1 ; ans = mid ; } else l = mid + 1 ; } return alphabets [ ans ] ; } int main ( ) { vector < char > letters { ' A ' , ' K ' , ' S ' } ; char K = ' L ' ; char result = nextGreatestAlphabet ( letters , K ) ; cout << result << endl ; return 0 ; }

Index/key variables: ans, mid
Accumulator variables: stdc