dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; Node ( int data ) { this -> data = data ; left = right = NULL ; } } ; void inOrder ( struct Node * root ) { stack < Node * > s ; Node * curr = root ; while ( curr != NULL || s . empty ( ) == false ) { while ( curr != NULL ) { s . push ( curr ) ; curr = curr -> left ; } curr = s . top ( ) ; s . pop ( ) ; cout << curr -> data << " ▁ " ; curr = curr -> right ; } } int main ( ) { struct Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; root -> left -> right = new Node ( 5 ) ; inOrder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; int numberOfPaths ( int m , int n ) { int count [ m ] [ n ] ; for ( int i = 0 ; i < m ; i ++ ) count [ i ] [ 0 ] = 1 ; for ( int j = 0 ; j < n ; j ++ ) count [ 0 ] [ j ] = 1 ; for ( int i = 1 ; i < m ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) } return count [ m - 1 ] [ n - 1 ] ; } int main ( ) { cout << numberOfPaths ( 3 , 3 ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > findSubsets ( vector < int > arr , int N ) { map < int , int > M ; for ( int i = 0 ; i < N ; i ++ ) { M [ arr [ i ] ] ++ ; } vector < int > subsets ; int I = 0 ; for ( auto playerEntry = M . begin ( ) ; playerEntry != M . end ( ) ; playerEntry ++ ) { subsets . push_back ( playerEntry -> second ) ; I ++ ; } return subsets ; } bool subsetSum ( vector < int > subsets , int N , int target ) { bool dp [ N + 1 ] [ target + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) dp [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= target ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; if ( j >= subsets [ i - 1 ] ) { dp [ i ] [ j ] |= dp [ i - 1 ] [ j - subsets [ i - 1 ] ] ; } } } return dp [ N ] [ target ] ; } void divideInto2Subset ( vector < int > arr , int N ) { vector < int > subsets = findSubsets ( arr , N ) ; if ( ( N ) % 2 == 1 ) { cout << " No " << endl ; return ; } int subsets_size = subsets . size ( ) ; bool isPossible = subsetSum ( subsets , subsets_size , N / 2 ) ; if ( isPossible ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } } int main ( ) { vector < int > arr { 2 , 1 , 2 , 3 } ; int N = arr . size ( ) ; divideInto2Subset ( arr , N ) ; return 0 ; }

Index/key variables: N, i, j, target
Accumulator variables: I, i, j, playerEntry, stdc
Iterator variables: i, j, playerEntry
C++ program:
#include <iostream>
using namespace std ; int max ( int a , int b ) { return ( a > b ) ? a : b ; } int max ( int a , int b , int c ) { return max ( a , max ( b , c ) ) ; } int maxProd ( int n ) { if ( n == 0 n == 1 ) return 0 ; int max_val = 0 ; for ( int i = 1 ; i < n ; i ++ ) max_val = max ( max_val , i * ( n - i ) , maxProd ( n - i ) * i ) ; return max_val ; } int main ( ) { cout << " Maximum ▁ Product ▁ is ▁ " << maxProd ( 10 ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define NUM_LINE  2
#define NUM_STATION  4
int min ( int a , int b ) { return a < b ? a : b ; } int carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) { int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ; T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ; T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ; for ( i = 1 ; i < NUM_STATION ; ++ i ) { T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ; T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ; } return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ; } int main ( ) { int a [ ] [ NUM_STATION ] = { { 4 , 5 , 3 , 2 } , { 2 , 10 , 1 , 4 } } ; int t [ ] [ NUM_STATION ] = { { 0 , 7 , 4 , 5 } , { 0 , 9 , 2 , 8 } } ; int e [ ] = { 10 , 12 } , x [ ] = { 18 , 7 } ; cout << carAssembly ( a , t , e , x ) ; return 0 ; }

Index/key variables: NUM_STATION, i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinInsertionsDP ( char str [ ] , int n ) { int table [ n ] [ n ] , l , h , gap ; memset ( table , 0 , sizeof ( table ) ) ; for ( gap = 1 ; gap < n ; ++ gap ) for ( l = 0 , h = gap ; h < n ; ++ l , ++ h ) table [ l ] [ h ] = ( str [ l ] == str [ h ] ) ? table [ l + 1 ] [ h - 1 ] : ( min ( table [ l ] [ h - 1 ] , table [ l + 1 ] [ h ] ) + 1 ) ; return table [ 0 ] [ n - 1 ] ; } int main ( ) { char str [ ] = " geeks " ; cout << findMinInsertionsDP ( str , strlen ( str ) ) ; return 0 ; }

Index/key variables: h, l, n
Accumulator variables: stdc
Iterator variables: gap, l
C++ program:
#include <limits.h>
#include <stdio.h>
int max ( int a , int b ) { return ( a > b ) ? a : b ; } int max ( int a , int b , int c ) { return max ( max ( a , b ) , c ) ; } int maxCrossingSum ( int arr [ ] , int l , int m , int h ) { int sum = 0 ; int left_sum = INT_MIN ; for ( int i = m ; i >= l ; i -- ) { sum = sum + arr [ i ] ; if ( sum > left_sum ) left_sum = sum ; } sum = 0 ; int right_sum = INT_MIN ; for ( int i = m + 1 ; i <= h ; i ++ ) { sum = sum + arr [ i ] ; if ( sum > right_sum ) right_sum = sum ; } return max ( left_sum + right_sum , left_sum , right_sum ) ; } int maxSubArraySum ( int arr [ ] , int l , int h ) { if ( l == h ) return arr [ l ] ; int m = ( l + h ) / 2 ; return max ( maxSubArraySum ( arr , l , m ) , maxSubArraySum ( arr , m + 1 , h ) , maxCrossingSum ( arr , l , m , h ) ) ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 5 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max_sum = maxSubArraySum ( arr , 0 , n - 1 ) ; printf ( " Maximum ▁ contiguous ▁ sum ▁ is ▁ % d STRNEWLINE " , max_sum ) ; getchar ( ) ; return 0 ; }

Index/key variables: i, l
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max ( int x , int y ) { return ( x > y ) ? x : y ; } class node { public : int data ; node * left , * right ; } ; int LISS ( node * root ) { if ( root == NULL ) return 0 ; int size_excl = LISS ( root -> left ) + LISS ( root -> right ) ; int size_incl = 1 ; if ( root -> left ) size_incl += LISS ( root -> left -> left ) + LISS ( root -> left -> right ) ; if ( root -> right ) size_incl += LISS ( root -> right -> left ) + LISS ( root -> right -> right ) ; return max ( size_incl , size_excl ) ; } node * newNode ( int data ) { node * temp = new node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { node * root = newNode ( 20 ) ; root -> left = newNode ( 8 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 12 ) ; root -> left -> right -> left = newNode ( 10 ) ; root -> left -> right -> right = newNode ( 14 ) ; root -> right = newNode ( 22 ) ; root -> right -> right = newNode ( 25 ) ; cout << " Size ▁ of ▁ the ▁ Largest " << " ▁ Independent ▁ Set ▁ is ▁ " << LISS ( root ) ; return 0 ; }

Accumulator variables: size_incl, stdc
Class/struct names: node
C++ program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
float findWater ( int i , int j , float X ) { if ( j > i ) { printf ( " Incorrect ▁ Inputn " ) ; exit ( 0 ) ; } float glass [ i * ( i + 1 ) / 2 ] ; memset ( glass , 0 , sizeof ( glass ) ) ; int index = 0 ; glass [ index ] = X ; for ( int row = 1 ; row <= i ; ++ row ) { for ( int col = 1 ; col <= row ; ++ col , ++ index ) { X = glass [ index ] ; glass [ index ] = ( X >= 1.0f ) ? 1.0f : X ; X = ( X >= 1.0f ) ? ( X - 1 ) : 0.0f ; glass [ index + row ] += X / 2 ; glass [ index + row + 1 ] += X / 2 ; } } return glass [ i * ( i - 1 ) / 2 + j - 1 ] ; } int main ( ) { int i = 2 , j = 2 ; float X = 2.0 ; printf ( " Amount ▁ of ▁ water ▁ in ▁ jth ▁ glass ▁ of ▁ ith ▁ row ▁ is : ▁ % f " , findWater ( i , j , X ) ) ; return 0 ; }

Index/key variables: index
Iterator variables: col, row
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Pair { public : int a ; int b ; } ; int maxChainLength ( Pair arr [ ] , int n ) { int i , j , max = 0 ; int * mcl = new int [ sizeof ( int ) * n ] ; for ( i = 0 ; i < n ; i ++ ) mcl [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] . a > arr [ j ] . b && mcl [ i ] < mcl [ j ] + 1 ) mcl [ i ] = mcl [ j ] + 1 ; for ( i = 0 ; i < n ; i ++ ) if ( max < mcl [ i ] ) max = mcl [ i ] ; return max ; } int main ( ) { Pair arr [ ] = { { 5 , 24 } , { 15 , 25 } , { 27 , 40 } , { 50 , 60 } } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Length ▁ of ▁ maximum ▁ size ▁ chain ▁ is ▁ " << maxChainLength ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Class/struct names: Pair
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minPalPartion ( string str ) { int n = str . length ( ) ; int C [ n ] [ n ] ; bool P [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { P [ i ] [ i ] = true ; C [ i ] [ i ] = 0 ; } for ( int L = 2 ; L <= n ; L ++ ) { for ( int i = 0 ; i < n - L + 1 ; i ++ ) { int j = i + L - 1 ; if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ; else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ; if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ; else { C [ i ] [ j ] = INT_MAX ; for ( int k = i ; k <= j - 1 ; k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ; } } } return C [ 0 ] [ n - 1 ] ; } int main ( ) { string str = " ababbbabbababa " ; cout << " Min ▁ cuts ▁ needed ▁ for ▁ Palindrome " " ▁ Partitioning ▁ is ▁ " << minPalPartion ( str ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: L, i, k, stdc
Iterator variables: L, i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getNode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return newNode ; } int countSubtreesWithSumX ( Node * root , int & count , int x ) { if ( ! root ) return 0 ; int ls = countSubtreesWithSumX ( root -> left , count , x ) ; int rs = countSubtreesWithSumX ( root -> right , count , x ) ; int sum = ls + rs + root -> data ; if ( sum == x ) count ++ ; return sum ; } int countSubtreesWithSumXUtil ( Node * root , int x ) { if ( ! root ) return 0 ; int count = 0 ; int ls = countSubtreesWithSumX ( root -> left , count , x ) ; int rs = countSubtreesWithSumX ( root -> right , count , x ) ; if ( ( ls + rs + root -> data ) == x ) count ++ ; return count ; } int main ( ) { Node * root = getNode ( 5 ) ; root -> left = getNode ( -10 ) ; root -> right = getNode ( 3 ) ; root -> left -> left = getNode ( 9 ) ; root -> left -> right = getNode ( 8 ) ; root -> right -> left = getNode ( -4 ) ; root -> right -> right = getNode ( 7 ) ; int x = 7 ; cout << " Count ▁ = ▁ " << countSubtreesWithSumXUtil ( root , x ) ; return 0 ; }

Accumulator variables: count, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minchanges ( vector < vector < int > > mat ) { int N = mat . size ( ) ; int M = mat [ 0 ] . size ( ) ; int i , j , ans = 0 , x ; map < int , int > mp ; for ( i = 0 ; i < N / 2 ; i ++ ) { for ( j = 0 ; j < M / 2 ; j ++ ) { mp [ mat [ i ] [ M - 1 - j ] ] ++ ; mp [ mat [ i ] [ j ] ] ++ ; mp [ mat [ N - 1 - i ] [ M - 1 - j ] ] ++ ; mp [ mat [ N - 1 - i ] [ j ] ] ++ ; x = 0 ; for ( auto it = mp . begin ( ) ; it != mp . end ( ) ; it ++ ) { x = max ( x , it -> second ) ; } ans = ans + 4 - x ; mp . clear ( ) ; } } if ( N % 2 == 1 ) { for ( i = 0 ; i < M / 2 ; i ++ ) { if ( mat [ N / 2 ] [ i ] != mat [ N / 2 ] [ M - 1 - i ] ) ans ++ ; } } if ( M % 2 == 1 ) { for ( i = 0 ; i < N / 2 ; i ++ ) { if ( mat [ i ] [ M / 2 ] != mat [ N - 1 - i ] [ M / 2 ] ) ans ++ ; } } cout << ans ; } int main ( ) { vector < vector < int > > mat { { 1 , 2 , 3 } , { 4 , 5 , 3 } , { 1 , 2 , 1 } } ; minchanges ( mat ) ; }

Index/key variables: i, j
Accumulator variables: ans, i, it, j, stdc
Iterator variables: i, it, j
C++ program:
#include <bits/stdc++.h>
#include <boost/algorithm/string.hpp>
using namespace std ; void checkprefix ( int A , int B ) { string s1 = to_string ( A ) ; string s2 = to_string ( B ) ; bool result ; result = boost :: algorithm :: starts_with ( s1 , s2 ) ; if ( result ) { cout << " Yes " ; } else { cout << " No " ; } } int main ( ) { int A = 12345 , B = 12 ; checkprefix ( A , B ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getNode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return newNode ; } int countSubtreesWithSumXUtil ( Node * root , int x ) { static int count = 0 ; static Node * ptr = root ; int l = 0 , r = 0 ; if ( root == NULL ) return 0 ; l += countSubtreesWithSumXUtil ( root -> left , x ) ; r += countSubtreesWithSumXUtil ( root -> right , x ) ; if ( l + r + root -> data == x ) count ++ ; if ( ptr != root ) return l + root -> data + r ; return count ; } int main ( ) { Node * root = getNode ( 5 ) ; root -> left = getNode ( -10 ) ; root -> right = getNode ( 3 ) ; root -> left -> left = getNode ( 9 ) ; root -> left -> right = getNode ( 8 ) ; root -> right -> left = getNode ( -4 ) ; root -> right -> right = getNode ( 7 ) ; int x = 7 ; cout << " Count ▁ = ▁ " << countSubtreesWithSumXUtil ( root , x ) ; return 0 ; }

Accumulator variables: count, l, r, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isValidPinCode ( string pinCode ) { const regex pattern ( " ^ [ 1-9 ] { 1 } [ 0-9 ] { 2 } \\ s { 0,1 } [ 0-9 ] { 3 } $ " ) ; if ( pinCode . empty ( ) ) { return false ; } if ( regex_match ( pinCode , pattern ) ) { return true ; } else { return false ; } } void print ( bool n ) { if ( n == 0 ) { cout << " False " << endl ; } else { cout << " True " << endl ; } } int main ( ) { string num1 = "132103" ; cout << num1 + " : ▁ " ; print ( isValidPinCode ( num1 ) ) ; string num2 = "201 ▁ 305" ; cout << num2 + " : ▁ " ; print ( isValidPinCode ( num2 ) ) ; string num3 = "014205" ; cout << num3 + " : ▁ " ; print ( isValidPinCode ( num3 ) ) ; string num4 = "1473598" ; cout << num4 + " : ▁ " ; print ( isValidPinCode ( num4 ) ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
#include <limits.h>
using namespace std ; int count_flips ( int a [ ] , int n , int k ) { bool set = false ; int ans = 0 , min_diff = INT_MAX ; for ( int i = 0 ; i < k ; i ++ ) { int curr_index = i , segment = 0 , count_zero = 0 , count_one = 0 ; while ( curr_index < n ) { if ( segment % 2 == 0 ) { if ( a [ curr_index ] == 1 ) count_zero ++ ; else count_one ++ ; } else { if ( a [ curr_index ] == 0 ) count_zero ++ ; else count_one ++ ; } curr_index = curr_index + k ; segment ++ ; } ans += min ( count_one , count_zero ) ; if ( count_one < count_zero ) set = ! set ; min_diff = min ( min_diff , abs ( count_zero - count_one ) ) ; } if ( set ) return ans ; else return ans + min_diff ; } int main ( ) { int n = 6 , k = 3 ; int a [ ] = { 0 , 0 , 1 , 1 , 0 , 0 } ; cout << count_flips ( a , n , k ) ; }

Index/key variables: curr_index
Accumulator variables: ans, count_one, count_zero, i, segment
Iterator variables: i
Boolean variables: set
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; int size ( Node * node ) { if ( node == NULL ) return 0 ; else return ( size ( node -> left ) + 1 + size ( node -> right ) ) ; } bool checkIsAP ( double arr [ ] , int n ) { if ( n == 1 ) return true ; sort ( arr , arr + n ) ; double d = arr [ 1 ] - arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ; return true ; } bool checkIsGP ( double arr [ ] , int n ) { if ( n == 1 ) return true ; sort ( arr , arr + n ) ; double r = arr [ 1 ] / arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] / arr [ i - 1 ] != r ) return false ; } return true ; } bool checkIsHP ( double arr [ ] , int n ) { if ( n == 1 ) { return true ; } double rec [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { rec [ i ] = ( ( 1 / arr [ i ] ) ) ; } sort ( rec , rec + n ) ; double d = ( rec [ 1 ] ) - ( rec [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { if ( rec [ i ] - rec [ i - 1 ] != d ) { return false ; } } return true ; } void checktype ( Node * root ) { int n = size ( root ) ; double arr [ n ] ; int i = 0 ; if ( root == NULL ) return ; queue < Node * > q ; q . push ( root ) ; while ( q . empty ( ) == false ) { Node * node = q . front ( ) ; arr [ i ] = node -> data ; i ++ ; q . pop ( ) ; if ( node -> left != NULL ) q . push ( node -> left ) ; if ( node -> right != NULL ) q . push ( node -> right ) ; } int flag = 0 ; if ( checkIsAP ( arr , n ) ) { cout << " Arithmetic ▁ Progression " << endl ; flag = 1 ; } else if ( checkIsGP ( arr , n ) ) { cout << " Geometric ▁ Progression " << endl ; flag = 1 ; } else if ( checkIsHP ( arr , n ) ) { cout << " Geometric ▁ Progression " << endl ; flag = 1 ; } else if ( flag == 0 ) { cout << " No " ; } } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int main ( ) { struct 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 ( 8 ) ; root -> right -> right -> left = newNode ( 6 ) ; root -> right -> right -> right = newNode ( 7 ) ; checktype ( root ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void q1 ( string , int ) ; void q2 ( string , int ) ; void q3 ( string , int ) ; void q4 ( string , int ) ; void q1 ( string s , int i ) { cout << " q1 - > " ; if ( i == s . length ( ) ) { cout << " NO ▁ STRNEWLINE " ; return ; } if ( s [ i ] == '0' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } void q2 ( string s , int i ) { cout << " q2 - > " ; if ( i == s . length ( ) ) { cout << " NO ▁ STRNEWLINE " ; return ; } if ( s [ i ] == '0' ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } void q3 ( string s , int i ) { cout << " q3 - > " ; if ( i == s . length ( ) ) { cout << " YES ▁ STRNEWLINE " ; return ; } if ( s [ i ] == '0' ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } void q4 ( string s , int i ) { cout << " q4 - > " ; if ( i == s . length ( ) ) { cout << " YES ▁ STRNEWLINE " ; return ; } if ( s [ i ] == '0' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } void q0 ( string s , int i ) { cout << " q0 - > " ; if ( i == s . length ( ) ) { cout << " NO ▁ STRNEWLINE " ; return ; } if ( s [ i ] == '0' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } int main ( ) { string s = "010101" ; cout << " State ▁ transitions ▁ are ▁ " ; q0 ( s , 0 ) ; }

Index/key variables: i
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool doMatch ( string A , string B ) { for ( int i = 0 ; i < A . length ( ) ; i ++ ) if ( A [ i ] != ' * ' && B [ i ] != ' * ' ) if ( A [ i ] != B [ i ] ) return false ; return true ; } int main ( ) { string A = " gee * sforgeeks " ; string B = " geeksforgeeks " ; cout << doMatch ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <string>
using namespace std ; int countSubstrs ( string s1 , string s2 ) { int ans = 0 ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { string s3 ; for ( int j = i ; j < s1 . length ( ) ; j ++ ) { s3 += s1 [ j ] ; if ( s2 . find ( s3 ) != string :: npos ) ans ++ ; } } return ans ; } int main ( ) { string s1 = " aab " , s2 = " aaaab " ; cout << countSubstrs ( s1 , s2 ) ; return 0 ; }

Index/key variables: j
Accumulator variables: ans, i, j, s3
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int factorial ( int N ) { int fact = 1 ; for ( int i = 1 ; i <= N ; i ++ ) fact = fact * i ; return fact ; } int nthTerm ( int N ) { return ( factorial ( N ) * ( N + 2 ) / 2 ) ; } int main ( ) { int N = 6 ; cout << nthTerm ( N ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sum = 0 , max_level = INT_MIN ; struct Node { int d ; Node * l ; Node * r ; } ; Node * createNode ( int d ) { Node * node ; node = new Node ; node -> d = d ; node -> l = NULL ; node -> r = NULL ; return node ; } void sumOfNodesAtMaxDepth ( Node * ro , int level ) { if ( ro == NULL ) return ; if ( level > max_level ) { sum = ro -> d ; max_level = level ; } else if ( level == max_level ) { sum = sum + ro -> d ; } sumOfNodesAtMaxDepth ( ro -> l , level + 1 ) ; sumOfNodesAtMaxDepth ( ro -> r , level + 1 ) ; } int main ( ) { Node * root ; root = createNode ( 1 ) ; root -> l = createNode ( 2 ) ; root -> r = createNode ( 3 ) ; root -> l -> l = createNode ( 4 ) ; root -> l -> r = createNode ( 5 ) ; root -> r -> l = createNode ( 6 ) ; root -> r -> r = createNode ( 7 ) ; sumOfNodesAtMaxDepth ( root , 0 ) ; cout << sum ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int regexMatch ( string text , string pat ) { int lenText = text . length ( ) ; int letPat = pat . length ( ) ; int i = 0 , j = 0 ; while ( i < letPat ) { if ( pat [ i ] != ' # ' ) { if ( pat [ i ] != text [ j ] ) return false ; i ++ ; j ++ ; } else { j ++ ; while ( text [ j ] != pat [ i + 1 ] ) j ++ ; i ++ ; } } return ( j == lenText ) ; } int main ( ) { string str = " ABABABA " ; string pat = " A # B # A " ; if ( regexMatch ( str , pat ) ) cout << " yes " ; else cout << " no " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
void translate ( char * str ) { int len = strlen ( str ) ; if ( len < 2 ) return ; int i = 0 ; int j = 0 ; while ( j < len - 1 ) { if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) { j = j + 2 ; str [ i ++ ] = ' C ' ; continue ; } str [ i ++ ] = str [ j ++ ] ; } if ( j == len - 1 ) str [ i ++ ] = str [ j ] ; str [ i ] = ' ' ; } 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
C++ program:
#include <bits/stdc++.h>
using namespace std ; int x [ ] = { -1 , -1 , -1 , 0 , 0 , 1 , 1 , 1 } ; int y [ ] = { -1 , 0 , 1 , -1 , 1 , -1 , 0 , 1 } ; bool search2D ( char * grid , int row , int col , string word , int R , int C ) { if ( * ( grid + row * C + col ) != word [ 0 ] ) return false ; int len = word . length ( ) ; for ( int dir = 0 ; dir < 8 ; dir ++ ) { int k , rd = row + x [ dir ] , cd = col + y [ dir ] ; for ( k = 1 ; k < len ; k ++ ) { if ( rd >= R rd < 0 cd > = C cd < 0 ) break ; if ( * ( grid + rd * C + cd ) != word [ k ] ) break ; rd += x [ dir ] , cd += y [ dir ] ; } if ( k == len ) return true ; } return false ; } void patternSearch ( char * grid , string word , int R , int C ) { for ( int row = 0 ; row < R ; row ++ ) for ( int col = 0 ; col < C ; col ++ ) if ( search2D ( grid , row , col , word , R , C ) ) cout << " pattern ▁ found ▁ at ▁ " << row << " , ▁ " << col << endl ; } int main ( ) { int R = 3 , C = 13 ; char grid [ R ] [ C ] = { " GEEKSFORGEEKS " , " GEEKSQUIZGEEK " , " IDEQAPRACTICE " } ; patternSearch ( ( char * ) grid , " GEEKS " , R , C ) ; cout << endl ; patternSearch ( ( char * ) grid , " EEE " , R , C ) ; return 0 ; }

Index/key variables: C, R, dir, k
Accumulator variables: cd, col, dir, k, rd, row, stdc
Iterator variables: col, dir, k, row