dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool endsWith ( string str , string pat ) { int patLen = pat . length ( ) ; int strLen = str . length ( ) ; if ( patLen > strLen ) return false ; patLen -- ; strLen -- ; while ( patLen >= 0 ) { if ( pat [ patLen ] != str [ strLen ] ) return false ; patLen -- ; strLen -- ; } return true ; } int countOfStrings ( string pat , int n , string sArr [ ] ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( endsWith ( sArr [ i ] , pat ) ) count ++ ; return count ; } int main ( ) { string pat = " ks " ; int n = 4 ; string sArr [ ] = { " geeks " , " geeksforgeeks " , " games " , " unit " } ; cout << countOfStrings ( pat , n , sArr ) ; return 0 ; }

Index/key variables: i, patLen, strLen
Accumulator variables: count, i, patLen, stdc, strLen
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getEndingIndex ( string str , int n , int i ) { i ++ ; while ( i < n ) { char curr = str [ i ] ; char prev = str [ i - 1 ] ; if ( ( curr == ' a ' && prev == ' z ' ) || ( curr - prev == 1 ) ) i ++ ; else break ; } return i - 1 ; } int largestSubStr ( string str , int n ) { int len = 0 ; int i = 0 ; while ( i < n ) { int end = getEndingIndex ( str , n , i ) ; len = max ( end - i + 1 , len ) ; i = end + 1 ; } return len ; } int main ( ) { string str = " abcabcdefabc " ; int n = str . length ( ) ; cout << ( largestSubStr ( str , n ) ) ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
ll getSum ( ll n , int d ) { if ( n < d ) return 0 ; while ( n % 10 != d ) n -- ; ll k = n / 10 ; return ( k + 1 ) * d + ( k * 10 + 10 * k * k ) / 2 ; } int main ( ) { ll n = 30 ; int d = 3 ; cout << getSum ( n , d ) ; return 0 ; }

Accumulator variables: n, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; map < int , int > getFrequencyMap ( int arr [ ] , int n ) { map < int , int > hashMap ; for ( int i = 0 ; i < n ; i ++ ) { hashMap [ arr [ i ] ] ++ ; } return hashMap ; } bool hasDigit ( map < int , int > * hashMap , int digit ) { if ( ( * hashMap ) [ digit ] ) { ( * hashMap ) [ digit ] -- ; return true ; } return false ; } string getMaxtime_value ( int arr [ ] , int n ) { map < int , int > hashMap = getFrequencyMap ( arr , n ) ; int i ; bool flag ; string time_value = " " ; flag = false ; for ( i = 2 ; i >= 0 ; i -- ) { if ( hasDigit ( & hashMap , i ) ) { flag = true ; time_value += ( char ) i + 48 ; break ; } } if ( ! flag ) return " - 1" ; flag = false ; if ( time_value [ 0 ] == '2' ) { for ( i = 3 ; i >= 0 ; i -- ) { if ( hasDigit ( & hashMap , i ) ) { flag = true ; time_value += ( char ) i + 48 ; break ; } } } else { for ( i = 9 ; i >= 0 ; i -- ) { if ( hasDigit ( & hashMap , i ) ) { flag = true ; time_value += ( char ) i + 48 ; break ; } } } if ( ! flag ) return " - 1" ; time_value += " : " ; flag = false ; for ( i = 5 ; i >= 0 ; i -- ) { if ( hasDigit ( & hashMap , i ) ) { flag = true ; time_value += ( char ) i + 48 ; break ; } } if ( ! flag ) return " - 1" ; flag = false ; for ( i = 9 ; i >= 0 ; i -- ) { if ( hasDigit ( & hashMap , i ) ) { flag = true ; time_value += ( char ) i + 48 ; break ; } } if ( ! flag ) return " - 1" ; return time_value ; } int main ( ) { int arr [ ] = { 0 , 0 , 0 , 9 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << ( getMaxtime_value ( arr , n ) ) ; return 0 ; }

Index/key variables: digit, i
Accumulator variables: i, stdc, time_value
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; string smallestFreq ( string S1 , string S2 ) { map < string , int > banned ; for ( int i = 0 ; i < S2 . length ( ) ; ++ i ) { string s = " " ; while ( i < S2 . length ( ) && S2 [ i ] != ' ▁ ' ) s += S2 [ i ++ ] ; banned [ s ] ++ ; } map < string , int > result ; string ans ; int freq = 0 ; for ( int i = 0 ; i < S1 . length ( ) ; ++ i ) { string s = " " ; while ( i < S1 . length ( ) && S1 [ i ] != ' ▁ ' ) s += S1 [ i ++ ] ; if ( banned [ s ] == 0 ) { result [ s ] ++ ; if ( result [ s ] > freq || ( result [ s ] == freq && s < ans ) ) { ans = s ; freq = result [ s ] ; } } } return ans ; } int main ( ) { string S1 = " geeks ▁ for ▁ geeks ▁ is ▁ best ▁ place ▁ to ▁ learn " ; string S2 = " bad ▁ place " ; cout << smallestFreq ( S1 , S2 ) ; return 0 ; }

Index/key variables: i, s
Accumulator variables: i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int replace ( string A , string B ) { int n = A . length ( ) , m = B . length ( ) ; int count = 0 , i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( A [ i + j ] != B [ j ] ) break ; } if ( j == m ) { count ++ ; i += m - 1 ; } } return count ; } int main ( ) { string str1 = " aaaaaaaa " ; string str2 = " aaa " ; cout << replace ( str1 , str2 ) ; return 0 ; }

Index/key variables: j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int n = 6 ; const int m = 8 ; int visited [ n ] [ m ] ; int result [ n ] [ m ] ; int COUNT ; bool is_valid ( int x , int y , int key , int input [ n ] [ m ] ) { if ( x < n && y < m && x >= 0 && y >= 0 ) { if ( visited [ x ] [ y ] == false && input [ x ] [ y ] == key ) return true ; else return false ; } else return false ; } void BFS ( int x , int y , int i , int j , int input [ n ] [ m ] ) { if ( x != y ) return ; visited [ i ] [ j ] = 1 ; COUNT ++ ; int x_move [ ] = { 0 , 0 , 1 , -1 } ; int y_move [ ] = { 1 , -1 , 0 , 0 } ; for ( int u = 0 ; u < 4 ; u ++ ) if ( is_valid ( i + y_move [ u ] , j + x_move [ u ] , x , input ) ) BFS ( x , y , i + y_move [ u ] , j + x_move [ u ] , input ) ; } void reset_visited ( ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) visited [ i ] [ j ] = 0 ; } void reset_result ( int key , int input [ n ] [ m ] ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( visited [ i ] [ j ] && input [ i ] [ j ] == key ) result [ i ] [ j ] = visited [ i ] [ j ] ; else result [ i ] [ j ] = 0 ; } } } void print_result ( int res ) { cout << " The ▁ largest ▁ connected ▁ " << " component ▁ of ▁ the ▁ grid ▁ is ▁ : " << res << " STRNEWLINE " ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( result [ i ] [ j ] ) cout << result [ i ] [ j ] << " ▁ " ; else cout << " . ▁ " ; } cout << " STRNEWLINE " ; } } void computeLargestConnectedGrid ( int input [ n ] [ m ] ) { int current_max = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { reset_visited ( ) ; COUNT = 0 ; if ( j + 1 < m ) BFS ( input [ i ] [ j ] , input [ i ] [ j + 1 ] , i , j , input ) ; if ( COUNT >= current_max ) { current_max = COUNT ; reset_result ( input [ i ] [ j ] , input ) ; } reset_visited ( ) ; COUNT = 0 ; if ( i + 1 < n ) BFS ( input [ i ] [ j ] , input [ i + 1 ] [ j ] , i , j , input ) ; if ( COUNT >= current_max ) { current_max = COUNT ; reset_result ( input [ i ] [ j ] , input ) ; } } } print_result ( current_max ) ; } int main ( ) { int input [ n ] [ m ] = { { 1 , 4 , 4 , 4 , 4 , 3 , 3 , 1 } , { 2 , 1 , 1 , 4 , 3 , 3 , 1 , 1 } , { 3 , 2 , 1 , 1 , 2 , 3 , 2 , 1 } , { 3 , 3 , 2 , 1 , 2 , 2 , 2 , 2 } , { 3 , 1 , 3 , 1 , 1 , 4 , 4 , 4 } , { 1 , 1 , 3 , 1 , 1 , 4 , 4 , 4 } } ; computeLargestConnectedGrid ( input ) ; return 0 ; }

Index/key variables: i, j, m, n, u, x, y
Accumulator variables: COUNT, i, j, stdc, u
Iterator variables: i, j, u
C++ program:
#include <bits/stdc++.h>
using namespace std ; int isSubstring ( string s1 , string s2 ) { int M = s1 . length ( ) ; int N = s2 . length ( ) ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) if ( s2 [ i + j ] != s1 [ j ] ) break ; if ( j == M ) return i ; } return -1 ; } int main ( ) { string s1 = " for " ; string s2 = " geeksforgeeks " ; int res = isSubstring ( s1 , s2 ) ; if ( res == -1 ) cout << " Not ▁ present " ; else cout << " Present ▁ at ▁ index ▁ " << res ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void split ( string str ) { int len = str . length ( ) ; if ( len == 1 ) { cout << ( " Not ▁ Possible " ) ; return ; } string s1 = " " , s2 = " " ; long num1 , num2 ; for ( int i = 0 ; i <= len / 2 ; i ++ ) { int flag = 0 ; s1 = str . substr ( 0 , i + 1 ) ; num1 = stoi ( ( s1 ) ) ; num2 = num1 + 1 ; s2 = to_string ( num2 ) ; int k = i + 1 ; while ( flag == 0 ) { int l = s2 . length ( ) ; if ( k + l > len ) { flag = 1 ; break ; } if ( ( str . substr ( k , k + l ) == s2 ) ) { flag = 0 ; num2 ++ ; k = k + l ; if ( k == len ) break ; s2 = to_string ( num2 ) ; l = s2 . length ( ) ; if ( k + 1 > len ) { flag = 1 ; break ; } } else flag = 1 ; } if ( flag == 0 ) { cout << " Possible ▁ " << s1 << endl ; break ; } else if ( flag == 1 && i > len / 2 - 1 ) { cout << " Not ▁ Possible " << endl ; break ; } } } int main ( ) { string str = "99100" ; split ( str ) ; return 0 ; }

Accumulator variables: i, num2, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ARRAY_SIZE ( a )  (sizeof(a) / sizeof(*a))
int internalSearch ( string needle , int row , int col , string hay [ ] , int row_max , int col_max , int xx ) { int found = 0 ; if ( row >= 0 && row <= row_max && col >= 0 && col <= col_max && needle [ xx ] == hay [ row ] [ col ] ) { char match = needle [ xx ] ; xx += 1 ; hay [ row ] [ col ] = 0 ; if ( needle [ xx ] == 0 ) { found = 1 ; } else { found += internalSearch ( needle , row , col + 1 , hay , row_max , col_max , xx ) ; found += internalSearch ( needle , row , col - 1 , hay , row_max , col_max , xx ) ; found += internalSearch ( needle , row + 1 , col , hay , row_max , col_max , xx ) ; found += internalSearch ( needle , row - 1 , col , hay , row_max , col_max , xx ) ; } hay [ row ] [ col ] = match ; } return found ; } int searchString ( string needle , int row , int col , string str [ ] , int row_count , int col_count ) { int found = 0 ; int r , c ; for ( r = 0 ; r < row_count ; ++ r ) { for ( c = 0 ; c < col_count ; ++ c ) { found += internalSearch ( needle , r , c , str , row_count - 1 , col_count - 1 , 0 ) ; } } return found ; } int main ( ) { string needle = " MAGIC " ; string input [ ] = { " BBABBM " , " CBMBBA " , " IBABBG " , " GOZBBI " , " ABBBBC " , " MCIGAM " } ; string str [ ARRAY_SIZE ( input ) ] ; int i ; for ( i = 0 ; i < ARRAY_SIZE ( input ) ; ++ i ) { str [ i ] = input [ i ] ; } cout << " count : ▁ " << searchString ( needle , 0 , 0 , str , ARRAY_SIZE ( str ) , str [ 0 ] . size ( ) ) << endl ; return 0 ; }

Index/key variables: col, i, row, xx
Accumulator variables: found, stdc, xx
Iterator variables: c, i, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; void KMP ( int m , int n , string str2 , string str1 ) { int pos = 0 , len = 0 ; int p [ m + 1 ] ; int k = 0 ; p [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ; if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ; p [ i ] = k ; } for ( int j = 0 , i = 0 ; i < m ; i ++ ) { while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ; if ( str1 [ j ] == str2 [ i ] ) j ++ ; if ( j > len ) { len = j ; pos = i - j + 1 ; } } cout << " Shift ▁ = ▁ " << pos << endl ; cout << " Prefix ▁ = ▁ " << str1 . substr ( 0 , len ) ; } int main ( ) { string str1 = " geeksforgeeks " ; string str2 = " forgeeksgeeks " ; int n = str1 . size ( ) ; str2 = str2 + str2 ; KMP ( 2 * n , n , str2 , str1 ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int patternCount ( string str ) { char last = str [ 0 ] ; int i = 1 , counter = 0 ; while ( i < str . size ( ) ) { if ( str [ i ] == '0' && last == '1' ) { while ( str [ i ] == '0' ) i ++ ; if ( str [ i ] == '1' ) counter ++ ; } last = str [ i ] ; i ++ ; } return counter ; } int main ( ) { string str = "1001ab010abc01001" ; cout << patternCount ( str ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: counter, i, stdc
C++ program:
#include <stdio.h>
#include <string.h>
void preprocess_strong_suffix ( int * shift , int * bpos , char * pat , int m ) { int i = m , j = m + 1 ; bpos [ i ] = j ; while ( i > 0 ) { while ( j <= m && pat [ i - 1 ] != pat [ j - 1 ] ) { if ( shift [ j ] == 0 ) shift [ j ] = j - i ; j = bpos [ j ] ; } i -- ; j -- ; bpos [ i ] = j ; } } void preprocess_case2 ( int * shift , int * bpos , char * pat , int m ) { int i , j ; j = bpos [ 0 ] ; for ( i = 0 ; i <= m ; i ++ ) { if ( shift [ i ] == 0 ) shift [ i ] = j ; if ( i == j ) j = bpos [ j ] ; } } void search ( char * text , char * pat ) { int s = 0 , j ; int m = strlen ( pat ) ; int n = strlen ( text ) ; int bpos [ m + 1 ] , shift [ m + 1 ] ; for ( int i = 0 ; i < m + 1 ; i ++ ) shift [ i ] = 0 ; preprocess_strong_suffix ( shift , bpos , pat , m ) ; preprocess_case2 ( shift , bpos , pat , m ) ; while ( s <= n - m ) { j = m - 1 ; while ( j >= 0 && pat [ j ] == text [ s + j ] ) j -- ; if ( j < 0 ) { printf ( " pattern ▁ occurs ▁ at ▁ shift ▁ = ▁ % d STRNEWLINE " , s ) ; s += shift [ 0 ] ; } else s += shift [ j + 1 ] ; } } int main ( ) { char text [ ] = " ABAAAABAACD " ; char pat [ ] = " ABA " ; search ( text , pat ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, s
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxPrefix ( char s [ ] , char t [ ] ) { int count = 0 ; for ( int i = 0 ; i < strlen ( t ) ; i ++ ) { if ( count == strlen ( s ) ) break ; if ( t [ i ] == s [ count ] ) count ++ ; } return count ; } int main ( ) { char S [ ] = " digger " ; char T [ ] = " biggerdiagram " ; cout << maxPrefix ( S , T ) << endl ; return 0 ; }

Index/key variables: count, i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
void translate ( char * str ) { if ( str [ 0 ] == ' ' ) return ; for ( int i = 1 ; str [ i ] != ' ' ; i ++ ) { if ( str [ i - 1 ] == ' A ' && str [ i ] == ' B ' ) { str [ i - 1 ] = ' C ' ; for ( int j = i ; str [ j ] != ' ' ; j ++ ) str [ j ] = str [ j + 1 ] ; } } return ; } int main ( ) { char str [ ] = " helloABworldABGfG " ; translate ( str ) ; printf ( " The ▁ modified ▁ string ▁ is ▁ : STRNEWLINE " ) ; printf ( " % s " , str ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ROW  3
#define COL  5
bool isvalid ( int row , int col , int prevRow , int prevCol ) { return ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ! ( row == prevRow && col == prevCol ) ; } int rowNum [ ] = { -1 , -1 , -1 , 0 , 0 , 1 , 1 , 1 } ; int colNum [ ] = { -1 , 0 , 1 , -1 , 1 , -1 , 0 , 1 } ; void DFS ( char mat [ ] [ COL ] , int row , int col , int prevRow , int prevCol , char * word , string path , int index , int n ) { if ( index > n mat [ row ] [ col ] != word [ index ] ) return ; path += string ( 1 , word [ index ] ) + " ( " + to_string ( row ) + " , ▁ " + to_string ( col ) + " ) ▁ " ; if ( index == n ) { cout << path << endl ; return ; } for ( int k = 0 ; k < 8 ; ++ k ) if ( isvalid ( row + rowNum [ k ] , col + colNum [ k ] , prevRow , prevCol ) ) DFS ( mat , row + rowNum [ k ] , col + colNum [ k ] , row , col , word , path , index + 1 , n ) ; } void findWords ( char mat [ ] [ COL ] , char * word , int n ) { for ( int i = 0 ; i < ROW ; ++ i ) for ( int j = 0 ; j < COL ; ++ j ) if ( mat [ i ] [ j ] == word [ 0 ] ) DFS ( mat , i , j , -1 , -1 , word , " " , 0 , n ) ; } int main ( ) { char mat [ ROW ] [ COL ] = { { ' B ' , ' N ' , ' E ' , ' Y ' , ' S ' } , { ' H ' , ' E ' , ' D ' , ' E ' , ' S ' } , { ' S ' , ' G ' , ' N ' , ' D ' , ' E ' } } ; char word [ ] = " DES " ; findWords ( mat , word , strlen ( word ) - 1 ) ; return 0 ; }

Index/key variables: COL, ROW, col, i, index, j, k, row
Accumulator variables: path, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int maxSize = 10 ; void randomHexInt ( int N ) { srand ( time ( 0 ) ) ; char hexChar [ ] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' } ; for ( int i = 0 ; i < N ; i ++ ) { int len = rand ( ) % maxSize + 1 ; for ( int j = 0 ; j < len ; j ++ ) { cout << hexChar [ rand ( ) % 16 ] ; } cout << ' ' ; } } int main ( ) { int N = 3 ; randomHexInt ( N ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkEqualArrays ( vector < string > arr , vector < string > brr , int N ) { int siz = arr [ 0 ] . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { sort ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; sort ( brr [ i ] . begin ( ) , brr [ i ] . end ( ) ) ; } sort ( arr . begin ( ) , arr . end ( ) ) ; sort ( brr . begin ( ) , brr . end ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { return false ; } } return true ; } int main ( ) { int N = 2 ; vector < string > arr = { " bcd " , " aac " } ; vector < string > brr = { " aca " , " dbc " } ; bool ans = checkEqualArrays ( arr , brr , N ) ; if ( ans ) cout << " true " ; else cout << " false " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxi = 0 ; string ans1 = " " ; void calculate ( string ans ) { int dp [ 26 ] = { 0 } ; for ( int i = 0 ; i < ans . length ( ) ; ++ i ) { dp [ ans [ i ] - ' A ' ] ++ ; } for ( int i = 0 ; i < 26 ; ++ i ) { if ( dp [ i ] % 2 == 1 ) { return ; } } if ( maxi < ans . length ( ) ) { maxi = ans . length ( ) ; ans1 = ans ; } } void longestString ( vector < string > arr , int index , string str ) { if ( index == arr . size ( ) ) { return ; } longestString ( arr , index + 1 , str ) ; str += arr [ index ] ; calculate ( str ) ; longestString ( arr , index + 1 , str ) ; } int main ( ) { vector < string > A = { " ABAB " , " ABF " , " CDA " , " AD " , " CCC " } ; longestString ( A , 0 , " " ) ; cout << ans1 << " ▁ " << ans1 . length ( ) ; return 0 ; }

Index/key variables: i, index
Accumulator variables: stdc, str
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string generateNumber ( string number ) { int temp = 0 , adding_number = 0 ; string result = " " ; int len = number . size ( ) ; for ( int i = len - 1 ; i >= 0 ; i -- ) { int digit = number [ i ] - '0' ; if ( temp % 2 == 0 ) { adding_number += 1 ; digit += adding_number ; if ( digit >= 10 ) { digit %= 9 ; if ( digit == 0 ) digit = 9 ; } } result = to_string ( digit ) + result ; temp += 1 ; } return result ; } int main ( ) { string S = "1345" ; cout << generateNumber ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: adding_number, digit, i, stdc, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findTheSum ( string str ) { string alpha ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) || ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) ) alpha . push_back ( str [ i ] ) ; } int score = 0 , n = 0 ; for ( int i = 0 ; i < alpha . length ( ) ; i ++ ) { if ( alpha [ i ] >= ' A ' && alpha [ i ] <= ' Z ' ) score += alpha [ i ] - ' A ' + 1 ; else score += alpha [ i ] - ' a ' + 1 ; } while ( score > 0 n > 9 ) { if ( score == 0 ) { score = n ; n = 0 ; } n += score % 10 ; score /= 10 ; } return n ; } int main ( ) { string S = " GeeksforGeeks " ; cout << findTheSum ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, n, score, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findK ( string s , char c ) { int n = s . length ( ) ; int diff ; int max = 0 ; int prev = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == c ) { diff = i - prev ; prev = i ; if ( diff > max ) { max = diff ; } } } if ( max == 0 ) return -1 ; return max ; } int main ( ) { string S = " abdegb " ; char ch = ' b ' ; cout << findK ( S , ch ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubsequence ( string S , int N , int K ) { int C = 0 , C1 = 0 , C0 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '1' ) C1 ++ ; else if ( S [ i ] == '0' ) C0 ++ ; } int B1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '1' ) B1 ++ ; else if ( S [ i ] == '0' ) C = C + ( C1 - B1 ) ; } int ans = C * K ; ans += ( C1 * C0 * ( ( ( K ) * ( K - 1 ) ) / 2 ) ) ; return ans ; } int main ( ) { string S = "230013110087" ; int K = 2 ; int N = S . length ( ) ; cout << countSubsequence ( S , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: B1, C0, C1, ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string convertString ( string S , int a , int b ) { int N = S . size ( ) ; for ( int i = 0 ; i < N / 2 ; ++ i ) { if ( S [ i ] == ' ? ' && S [ N - i - 1 ] != ' ? ' ) { S [ i ] = S [ N - i - 1 ] ; } else if ( S [ i ] != ' ? ' && S [ N - i - 1 ] == ' ? ' ) { S [ N - i - 1 ] = S [ i ] ; } } a = a - count ( S . begin ( ) , S . end ( ) , '0' ) ; b = b - count ( S . begin ( ) , S . end ( ) , '1' ) ; for ( int i = 0 ; i < N / 2 ; ++ i ) { if ( S [ i ] == ' ? ' && S [ N - i - 1 ] == ' ? ' ) { if ( a > b ) { S [ i ] = S [ N - i - 1 ] = '0' ; a -= 2 ; } else { S [ i ] = S [ N - i - 1 ] = '1' ; b -= 2 ; } } } if ( S [ N / 2 ] == ' ? ' ) { if ( a > b ) { S [ N / 2 ] = '0' ; a -- ; } else { S [ N / 2 ] = '1' ; b -- ; } } if ( a == 0 && b == 0 ) { return S ; } else { return " - 1" ; } } int main ( ) { string S = "10 ? ? ? ? ?1" ; int a = 4 , b = 4 ; cout << convertString ( S , a , b ) ; return 0 ; }

Index/key variables: i
Accumulator variables: a, b, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Find ( vector < int > & parent , int a ) { return parent [ a ] = ( parent [ a ] == a ? a : Find ( parent , parent [ a ] ) ) ; } void Union ( vector < int > & parent , vector < int > & rank , int a , int b ) { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( rank [ a ] == rank [ b ] ) rank [ a ] ++ ; if ( rank [ a ] > rank [ b ] ) parent [ b ] = a ; else parent [ a ] = b ; } void numOfDistinctStrings ( string arr [ ] , int N ) { vector < int > parent ( 27 ) ; vector < int > rank ( 27 , 0 ) ; for ( int j = 0 ; j < 27 ; j ++ ) { parent [ j ] = j ; } vector < bool > total ( 26 , false ) ; vector < bool > current ( 26 , false ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { current [ j ] = false ; } for ( char ch : arr [ i ] ) { current [ ch - ' a ' ] = true ; } for ( int j = 0 ; j < 26 ; j ++ ) { if ( current [ j ] ) { total [ j ] = true ; Union ( parent , rank , arr [ i ] [ 0 ] - ' a ' , j ) ; } } } int distCount = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( total [ i ] && Find ( parent , i ) == i ) { distCount ++ ; } } cout << distCount << endl ; } int main ( ) { string arr [ ] = { " a " , " ab " , " b " , " d " } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; numOfDistinctStrings ( arr , N ) ; return 0 ; }

Index/key variables: a, b, i, j
Accumulator variables: distCount, i, j, stdc
Iterator variables: ch, i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSwaps ( string s ) { int ones = 0 , zeros = 0 ; int N = s . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '1' ) ones ++ ; else zeros ++ ; } if ( ( N % 2 == 0 && ones != zeros ) || ( N % 2 == 1 && abs ( ones - zeros ) != 1 ) ) { return -1 ; } int ans_1 = 0 ; int j = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '1' ) { ans_1 += abs ( j - i ) ; j += 2 ; } } int ans_0 = 0 ; int k = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '0' ) { ans_0 += abs ( k - i ) ; k += 2 ; } } if ( N % 2 == 0 ) return min ( ans_1 , ans_0 ) ; else { if ( ones > zeros ) return ans_1 ; else return ans_0 ; } } int main ( ) { string S = "110100" ; cout << minSwaps ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans_0, ans_1, i, j, k, ones, stdc, zeros
Iterator variables: i