dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int root ( int arr [ ] , int i ) { while ( arr [ i ] != i ) { arr [ i ] = arr [ arr [ i ] ] ; i = arr [ i ] ; } return i ; } void weighted_union ( int arr [ ] , int rank [ ] , int a , int b ) { int root_a = root ( arr , a ) ; int root_b = root ( arr , b ) ; if ( rank [ root_a ] < rank [ root_b ] ) { arr [ root_a ] = arr [ root_b ] ; rank [ root_b ] += rank [ root_a ] ; } else { arr [ root_b ] = arr [ root_a ] ; rank [ root_a ] += rank [ root_b ] ; } } bool areSame ( int arr [ ] , int a , int b ) { return ( root ( arr , a ) == root ( arr , b ) ) ; } void query ( int type , int x , int y , int arr [ ] , int rank [ ] ) { if ( type == 1 ) { if ( areSame ( arr , x , y ) == true ) cout << " Yes " << endl ; else cout << " No " << endl ; } else if ( type == 2 ) { if ( areSame ( arr , x , y ) == false ) weighted_union ( arr , rank , x , y ) ; } } int main ( ) { int n = 7 ; int arr [ n ] , rank [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = i ; rank [ i ] = 1 ; } int q = 11 ; query ( 1 , 0 , 1 , arr , rank ) ; query ( 2 , 0 , 1 , arr , rank ) ; query ( 2 , 1 , 2 , arr , rank ) ; query ( 1 , 0 , 2 , arr , rank ) ; query ( 2 , 0 , 2 , arr , rank ) ; query ( 2 , 2 , 3 , arr , rank ) ; query ( 2 , 3 , 4 , arr , rank ) ; query ( 1 , 0 , 5 , arr , rank ) ; query ( 2 , 4 , 5 , arr , rank ) ; query ( 2 , 5 , 6 , arr , rank ) ; query ( 1 , 2 , 6 , arr , rank ) ; return 0 ; }

Index/key variables: i, n, root_a, root_b
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <queue>
using namespace std ; struct Node { int data ; Node * left ; Node * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> right = node -> left = NULL ; return node ; } void printSpecificLevelOrder ( Node * root ) { if ( root == NULL ) return ; cout << root -> data ; if ( root -> left != NULL ) cout << " ▁ " << root -> left -> data << " ▁ " << root -> right -> data ; if ( root -> left -> left == NULL ) return ; queue < Node * > q ; q . push ( root -> left ) ; q . push ( root -> right ) ; Node * first = NULL , * second = NULL ; while ( ! q . empty ( ) ) { first = q . front ( ) ; q . pop ( ) ; second = q . front ( ) ; q . pop ( ) ; cout << " ▁ " << first -> left -> data << " ▁ " << second -> right -> data ; cout << " ▁ " << first -> right -> data << " ▁ " << second -> left -> data ; if ( first -> left -> left != NULL ) { q . push ( first -> left ) ; q . push ( second -> right ) ; q . push ( first -> right ) ; q . push ( second -> left ) ; } } } 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 -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 8 ) ; root -> left -> left -> right = newNode ( 9 ) ; root -> left -> right -> left = newNode ( 10 ) ; root -> left -> right -> right = newNode ( 11 ) ; root -> right -> left -> left = newNode ( 12 ) ; root -> right -> left -> right = newNode ( 13 ) ; root -> right -> right -> left = newNode ( 14 ) ; root -> right -> right -> right = newNode ( 15 ) ; root -> left -> left -> left -> left = newNode ( 16 ) ; root -> left -> left -> left -> right = newNode ( 17 ) ; root -> left -> left -> right -> left = newNode ( 18 ) ; root -> left -> left -> right -> right = newNode ( 19 ) ; root -> left -> right -> left -> left = newNode ( 20 ) ; root -> left -> right -> left -> right = newNode ( 21 ) ; root -> left -> right -> right -> left = newNode ( 22 ) ; root -> left -> right -> right -> right = newNode ( 23 ) ; root -> right -> left -> left -> left = newNode ( 24 ) ; root -> right -> left -> left -> right = newNode ( 25 ) ; root -> right -> left -> right -> left = newNode ( 26 ) ; root -> right -> left -> right -> right = newNode ( 27 ) ; root -> right -> right -> left -> left = newNode ( 28 ) ; root -> right -> right -> left -> right = newNode ( 29 ) ; root -> right -> right -> right -> left = newNode ( 30 ) ; root -> right -> right -> right -> right = newNode ( 31 ) ; cout << " Specific ▁ Level ▁ Order ▁ traversal ▁ of ▁ binary ▁ tree ▁ is ▁ STRNEWLINE " ; printSpecificLevelOrder ( root ) ; return 0 ; }

Class/struct names: Node
C++ program:
#include <iostream>
#include <limits.h>
#include <queue>
#include <string.h>
using namespace std ; #define V  6
bool bfs ( int rGraph [ V ] [ V ] , int s , int t , int parent [ ] ) { bool visited [ V ] ; memset ( visited , 0 , sizeof ( visited ) ) ; queue < int > q ; q . push ( s ) ; visited [ s ] = true ; parent [ s ] = -1 ; while ( ! q . empty ( ) ) { int u = q . front ( ) ; q . pop ( ) ; for ( int v = 0 ; v < V ; v ++ ) { if ( visited [ v ] == false && rGraph [ u ] [ v ] > 0 ) { if ( v == t ) { parent [ v ] = u ; return true ; } q . push ( v ) ; parent [ v ] = u ; visited [ v ] = true ; } } } return false ; } int fordFulkerson ( int graph [ V ] [ V ] , int s , int t ) { int u , v ; int rGraph [ V ] [ V ] ; for ( u = 0 ; u < V ; u ++ ) for ( v = 0 ; v < V ; v ++ ) rGraph [ u ] [ v ] = graph [ u ] [ v ] ; int parent [ V ] ; int max_flow = 0 ; while ( bfs ( rGraph , s , t , parent ) ) { int path_flow = INT_MAX ; for ( v = t ; v != s ; v = parent [ v ] ) { u = parent [ v ] ; path_flow = min ( path_flow , rGraph [ u ] [ v ] ) ; } for ( v = t ; v != s ; v = parent [ v ] ) { u = parent [ v ] ; rGraph [ u ] [ v ] -= path_flow ; rGraph [ v ] [ u ] += path_flow ; } max_flow += path_flow ; } return max_flow ; } int main ( ) { int graph [ V ] [ V ] = { { 0 , 16 , 13 , 0 , 0 , 0 } , { 0 , 0 , 10 , 12 , 0 , 0 } , { 0 , 4 , 0 , 0 , 14 , 0 } , { 0 , 0 , 9 , 0 , 0 , 20 } , { 0 , 0 , 0 , 7 , 0 , 4 } , { 0 , 0 , 0 , 0 , 0 , 0 } } ; cout << " The ▁ maximum ▁ possible ▁ flow ▁ is ▁ " << fordFulkerson ( graph , 0 , 5 ) ; return 0 ; }

Index/key variables: V, s, u, v
Accumulator variables: max_flow, u, v
Iterator variables: u, v
C++ program:
#include <iostream>
#include <limits.h>
#include <string.h>
#include <queue>
using namespace std ; #define V  8
bool bfs ( int rGraph [ V ] [ V ] , int s , int t , int parent [ ] ) { bool visited [ V ] ; memset ( visited , 0 , sizeof ( visited ) ) ; queue < int > q ; q . push ( s ) ; visited [ s ] = true ; parent [ s ] = -1 ; while ( ! q . empty ( ) ) { int u = q . front ( ) ; q . pop ( ) ; for ( int v = 0 ; v < V ; v ++ ) { if ( visited [ v ] == false && rGraph [ u ] [ v ] > 0 ) { q . push ( v ) ; parent [ v ] = u ; visited [ v ] = true ; } } } return ( visited [ t ] == true ) ; } int findDisjointPaths ( int graph [ V ] [ V ] , int s , int t ) { int u , v ; int rGraph [ V ] [ V ] ; for ( u = 0 ; u < V ; u ++ ) for ( v = 0 ; v < V ; v ++ ) rGraph [ u ] [ v ] = graph [ u ] [ v ] ; int parent [ V ] ; int max_flow = 0 ; while ( bfs ( rGraph , s , t , parent ) ) { int path_flow = INT_MAX ; for ( v = t ; v != s ; v = parent [ v ] ) { u = parent [ v ] ; path_flow = min ( path_flow , rGraph [ u ] [ v ] ) ; } for ( v = t ; v != s ; v = parent [ v ] ) { u = parent [ v ] ; rGraph [ u ] [ v ] -= path_flow ; rGraph [ v ] [ u ] += path_flow ; } max_flow += path_flow ; } return max_flow ; } int main ( ) { int graph [ V ] [ V ] = { { 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 } , { 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 } , { 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 } , { 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } } ; int s = 0 ; int t = 7 ; cout << " There ▁ can ▁ be ▁ maximum ▁ " << findDisjointPaths ( graph , s , t ) << " ▁ edge - disjoint ▁ paths ▁ from ▁ " << s << " ▁ to ▁ " << t ; return 0 ; }

Index/key variables: V, s, t, u, v
Accumulator variables: max_flow, u, v
Iterator variables: u, v
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> right = node -> left = NULL ; return node ; } void printSpecificLevelOrderUtil ( Node * root , stack < Node * > & s ) { if ( root == NULL ) return ; queue < Node * > q ; q . push ( root -> left ) ; q . push ( root -> right ) ; Node * first = NULL , * second = NULL ; while ( ! q . empty ( ) ) { first = q . front ( ) ; q . pop ( ) ; second = q . front ( ) ; q . pop ( ) ; s . push ( second -> left ) ; s . push ( first -> right ) ; s . push ( second -> right ) ; s . push ( first -> left ) ; if ( first -> left -> left != NULL ) { q . push ( first -> right ) ; q . push ( second -> left ) ; q . push ( first -> left ) ; q . push ( second -> right ) ; } } } void printSpecificLevelOrder ( Node * root ) { stack < Node * > s ; s . push ( root ) ; if ( root -> left != NULL ) { s . push ( root -> right ) ; s . push ( root -> left ) ; } if ( root -> left -> left != NULL ) printSpecificLevelOrderUtil ( root , s ) ; while ( ! s . empty ( ) ) { cout << s . top ( ) -> data << " ▁ " ; s . pop ( ) ; } } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; cout << " Specific ▁ Level ▁ Order ▁ traversal ▁ of ▁ binary ▁ " " tree ▁ is ▁ STRNEWLINE " ; printSpecificLevelOrder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
if ( inMST [ v ] == false && key [ v ] > weight ) { key [ v ] = weight ; pq . push ( make_pair ( key [ v ] , v ) ) ; parent [ v ] = u ; }

Index/key variables: v
C++ program:
#include <bits/stdc++.h>
using namespace std ; void addEdge ( vector < pair < int , int > > adj [ ] , int u , int v , int wt ) { adj [ u ] . push_back ( make_pair ( v , wt ) ) ; adj [ v ] . push_back ( make_pair ( u , wt ) ) ; } void printGraph ( vector < pair < int , int > > adj [ ] , int V ) { int v , w ; for ( int u = 0 ; u < V ; u ++ ) { cout << " Node ▁ " << u << " ▁ makes ▁ an ▁ edge ▁ with ▁ STRNEWLINE " ; for ( auto it = adj [ u ] . begin ( ) ; it != adj [ u ] . end ( ) ; it ++ ) { v = it -> first ; w = it -> second ; cout << " TABSYMBOL Node ▁ " << v << " ▁ with ▁ edge ▁ weight ▁ = " << w << " STRNEWLINE " ; } cout << " STRNEWLINE " ; } } int main ( ) { int V = 5 ; vector < pair < int , int > > adj [ V ] ; addEdge ( adj , 0 , 1 , 10 ) ; addEdge ( adj , 0 , 4 , 20 ) ; addEdge ( adj , 1 , 2 , 30 ) ; addEdge ( adj , 1 , 3 , 40 ) ; addEdge ( adj , 1 , 4 , 50 ) ; addEdge ( adj , 2 , 3 , 60 ) ; addEdge ( adj , 3 , 4 , 70 ) ; printGraph ( adj , V ) ; return 0 ; }

Index/key variables: V, u, v
Accumulator variables: it, stdc, u
Iterator variables: it, u
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxindex ( int * dist , int n ) { int mi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dist [ i ] > dist [ mi ] ) mi = i ; } return mi ; } void selectKcities ( int n , int weights [ 4 ] [ 4 ] , int k ) { int * dist = new int [ n ] ; vector < int > centers ; for ( int i = 0 ; i < n ; i ++ ) { dist [ i ] = INT_MAX ; } int max = 0 ; for ( int i = 0 ; i < k ; i ++ ) { centers . push_back ( max ) ; for ( int j = 0 ; j < n ; j ++ ) { dist [ j ] = min ( dist [ j ] , weights [ max ] [ j ] ) ; } max = maxindex ( dist , n ) ; } cout << endl << dist [ max ] << endl ; for ( int i = 0 ; i < centers . size ( ) ; i ++ ) { cout << centers [ i ] << " ▁ " ; } cout << endl ; } int main ( ) { int n = 4 ; int weights [ 4 ] [ 4 ] = { { 0 , 4 , 8 , 5 } , { 4 , 0 , 10 , 7 } , { 8 , 10 , 0 , 9 } , { 5 , 7 , 9 , 0 } } ; int k = 2 ; selectKcities ( n , weights , k ) ; }

Index/key variables: i, j, max, mi, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printCircuit ( vector < vector < int > > adj ) { unordered_map < int , int > edge_count ; for ( int i = 0 ; i < adj . size ( ) ; i ++ ) { edge_count [ i ] = adj [ i ] . size ( ) ; } if ( ! adj . size ( ) ) return ; stack < int > curr_path ; vector < int > circuit ; curr_path . push ( 0 ) ; int curr_v = 0 ; while ( ! curr_path . empty ( ) ) { if ( edge_count [ curr_v ] ) { curr_path . push ( curr_v ) ; int next_v = adj [ curr_v ] . back ( ) ; edge_count [ curr_v ] -- ; adj [ curr_v ] . pop_back ( ) ; curr_v = next_v ; } else { circuit . push_back ( curr_v ) ; curr_v = curr_path . top ( ) ; curr_path . pop ( ) ; } } for ( int i = circuit . size ( ) - 1 ; i >= 0 ; i -- ) { cout << circuit [ i ] ; if ( i ) cout << " ▁ - > ▁ " ; } } int main ( ) { vector < vector < int > > adj1 , adj2 ; adj1 . resize ( 3 ) ; adj1 [ 0 ] . push_back ( 1 ) ; adj1 [ 1 ] . push_back ( 2 ) ; adj1 [ 2 ] . push_back ( 0 ) ; printCircuit ( adj1 ) ; cout << endl ; adj2 . resize ( 7 ) ; adj2 [ 0 ] . push_back ( 1 ) ; adj2 [ 0 ] . push_back ( 6 ) ; adj2 [ 1 ] . push_back ( 2 ) ; adj2 [ 2 ] . push_back ( 0 ) ; adj2 [ 2 ] . push_back ( 3 ) ; adj2 [ 3 ] . push_back ( 4 ) ; adj2 [ 4 ] . push_back ( 2 ) ; adj2 [ 4 ] . push_back ( 5 ) ; adj2 [ 5 ] . push_back ( 0 ) ; adj2 [ 6 ] . push_back ( 4 ) ; printCircuit ( adj2 ) ; return 0 ; }

Index/key variables: curr_v, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int data ; Node * left ; Node * right ; Node ( int value ) { data = value ; left = NULL ; right = NULL ; } } ; void specific_level_order_traversal ( Node * root ) { queue < Node * > q ; stack < vector < int > > s ; q . push ( root ) ; int sz ; while ( ! q . empty ( ) ) { vector < int > v ; sz = q . size ( ) ; for ( int i = 0 ; i < sz ; ++ i ) { Node * temp = q . front ( ) ; q . pop ( ) ; v . push_back ( temp -> data ) ; if ( temp -> left != NULL ) q . push ( temp -> left ) ; if ( temp -> right != NULL ) q . push ( temp -> right ) ; } s . push ( v ) ; } while ( ! s . empty ( ) ) { vector < int > v = s . top ( ) ; s . pop ( ) ; for ( int i = 0 , j = v . size ( ) - 1 ; i < j ; ++ i ) { cout << v [ i ] << " ▁ " << v [ j ] << " ▁ " ; j -- ; } } cout << root -> data ; } int main ( ) { Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; cout << " Specific ▁ Level ▁ Order ▁ traversal ▁ of ▁ binary ▁ " " tree ▁ is ▁ STRNEWLINE " ; specific_level_order_traversal ( root ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: j, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define V  4
void multiply ( int A [ ] [ V ] , int B [ ] [ V ] , int C [ ] [ V ] ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { C [ i ] [ j ] = 0 ; for ( int k = 0 ; k < V ; k ++ ) C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ] ; } } } int getTrace ( int graph [ ] [ V ] ) { int trace = 0 ; for ( int i = 0 ; i < V ; i ++ ) trace += graph [ i ] [ i ] ; return trace ; } int triangleInGraph ( int graph [ ] [ V ] ) { int aux2 [ V ] [ V ] ; int aux3 [ V ] [ V ] ; for ( int i = 0 ; i < V ; ++ i ) for ( int j = 0 ; j < V ; ++ j ) aux2 [ i ] [ j ] = aux3 [ i ] [ j ] = 0 ; multiply ( graph , graph , aux2 ) ; multiply ( graph , aux2 , aux3 ) ; int trace = getTrace ( aux3 ) ; return trace / 6 ; } int main ( ) { int graph [ V ] [ V ] = { { 0 , 1 , 1 , 0 } , { 1 , 0 , 1 , 1 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } } ; printf ( " Total ▁ number ▁ of ▁ Triangle ▁ in ▁ Graph ▁ : ▁ % d STRNEWLINE " , triangleInGraph ( graph ) ) ; return 0 ; }

Index/key variables: V, i, j, k
Accumulator variables: i, j, k, stdc, trace
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } int countSubsequences ( string str1 , string str2 ) { int freq1 [ SIZE ] , freq2 [ SIZE ] ; int n1 = str1 . size ( ) ; int n2 = str2 . size ( ) ; memset ( freq1 , 0 , sizeof ( freq1 ) ) ; memset ( freq2 , 0 , sizeof ( freq2 ) ) ; for ( int i = 0 ; i < n1 ; i ++ ) freq1 [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n2 ; i ++ ) freq2 [ str2 [ i ] - ' a ' ] ++ ; int count = 1 ; for ( int i = 0 ; i < SIZE ; i ++ ) if ( freq2 [ i ] != 0 ) { if ( freq2 [ i ] <= freq1 [ i ] ) count = count * binomialCoeff ( freq1 [ i ] , freq2 [ i ] ) ; else return 0 ; } return count ; } int main ( ) { string str1 = " abacd " ; string str2 = " abc " ; cout << " Count ▁ = ▁ " << countSubsequences ( str1 , str2 ) ; return 0 ; }

Index/key variables: SIZE, i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int * fwd , * bwd ; void preProcess ( string a , string b ) { int n = a . size ( ) ; fwd = new int [ n ] ( ) ; bwd = new int [ n ] ( ) ; int j = 0 ; for ( int i = 1 ; i <= a . size ( ) ; i ++ ) { if ( j < b . size ( ) && a [ i - 1 ] == b [ j ] ) j ++ ; fwd [ i ] = j ; } j = 0 ; for ( int i = a . size ( ) ; i >= 1 ; i -- ) { if ( j < b . size ( ) && a [ i - 1 ] == b [ b . size ( ) - j - 1 ] ) j ++ ; bwd [ i ] = j ; } } void query ( string a , string b , int x , int y ) { if ( ( x - 1 + a . size ( ) - y ) < b . size ( ) ) { cout << " No STRNEWLINE " ; return ; } if ( fwd [ x - 1 ] + bwd [ y + 1 ] >= b . size ( ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; } int main ( ) { string a = " abcabcxy " , b = " acy " ; preProcess ( a , b ) ; int x = 2 , y = 5 ; query ( a , b , x , y ) ; x = 3 , y = 6 ; query ( a , b , x , y ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findOccurrences ( string str , string substr ) { int counter = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == substr [ 0 ] ) { for ( int j = i + 1 ; j < str . length ( ) ; j ++ ) { if ( str [ j ] == substr [ 1 ] ) { for ( int k = j + 1 ; k < str . length ( ) ; k ++ ) { if ( str [ k ] == substr [ 2 ] ) counter ++ ; } } } } } return counter ; } int main ( ) { string str = " GFGFGYSYIOIWIN " ; string substr = " GFG " ; cout << findOccurrences ( str , substr ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: counter, i, j, k
Iterator variables: i, j, k
C++ program:
#include <iostream>
using namespace std ; int findOccurrences ( string str , string substr ) { int n = str . length ( ) ; int preLeft [ n ] = { 0 } ; int preRight [ n ] = { 0 } ; if ( str [ 0 ] == substr [ 0 ] ) preLeft [ 0 ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { if ( str [ i ] == substr [ 0 ] ) preLeft [ i ] = preLeft [ i - 1 ] + 1 ; else preLeft [ i ] = preLeft [ i - 1 ] ; } if ( str [ n - 1 ] == substr [ 2 ] ) preRight [ n - 1 ] ++ ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( str [ i ] == substr [ 2 ] ) preRight [ i ] = preRight [ i + 1 ] + 1 ; else preRight [ i ] = preRight [ i + 1 ] ; } int counter = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( str [ i ] == str [ 1 ] ) { int total = preLeft [ i - 1 ] * preRight [ i + 1 ] ; counter += total ; } } return counter ; } int main ( ) { string str = " GFGFGYSYIOIWIN " ; string substr = " GFG " ; cout << findOccurrences ( str , substr ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: counter, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void largestPalin ( char num [ ] , int n ) { if ( n <= 3 ) return ; int mid = n / 2 - 1 ; int rightMax [ mid + 1 ] , right ; rightMax [ mid ] = -1 ; right = mid ; for ( int i = mid - 1 ; i >= 0 ; i -- ) { if ( num [ i ] < num [ right ] ) rightMax [ i ] = right ; else { rightMax [ i ] = -1 ; right = i ; } } for ( int i = 0 ; i <= mid ; i ++ ) { if ( rightMax [ i ] != -1 ) { swap ( num [ i ] , num [ rightMax [ i ] ] ) ; swap ( num [ n - i - 1 ] , num [ n - rightMax [ i ] - 1 ] ) ; break ; } } } int main ( ) { char num [ ] = "4697557964" ; int n = strlen ( num ) ; largestPalin ( num , n ) ; cout << " Largest ▁ Palindrome : ▁ " << num ; return 0 ; }

Index/key variables: i, mid, right
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <string>
using namespace std ; string compute ( string str , int n ) { string reverseAlphabet = " zyxwvutsrqponmlkjihgfedcba " ; int l = str . length ( ) ; for ( int i = n ; i < l ; i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - ' a ' ] ; return str ; } int main ( ) { string str = " pneumonia " ; int n = 4 ; string answer = compute ( str , n - 1 ) ; cout << answer ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isBipartite ( int V , vector < int > adj [ ] ) { vector < int > col ( V , -1 ) ; queue < pair < int , int > > q ; for ( int i = 0 ; i < V ; i ++ ) { if ( col [ i ] == -1 ) { q . push ( { i , 0 } ) ; col [ i ] = 0 ; while ( ! q . empty ( ) ) { pair < int , int > p = q . front ( ) ; q . pop ( ) ; int v = p . first ; int c = p . second ; for ( int j : adj [ v ] ) { if ( col [ j ] == c ) return 0 ; if ( col [ j ] == -1 ) { col [ j ] = ( c ) ? 0 : 1 ; q . push ( { j , col [ j ] } ) ; } } } } } return 1 ; } int main ( ) { int V , E ; V = 4 , E = 8 ; vector < int > adj [ V ] ; adj [ 0 ] = { 1 , 3 } ; adj [ 1 ] = { 0 , 2 } ; adj [ 2 ] = { 1 , 3 } ; adj [ 3 ] = { 0 , 2 } ; bool ans = isBipartite ( V , adj ) ; if ( ans ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; return 0 ; }

Index/key variables: V, i, j, v
Accumulator variables: i, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findString ( string str , int n , int k ) { if ( k == 0 ) { cout << str << endl ; return ; } string str2 = str ; int p = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str2 [ i ] != ' a ' ) { str2 [ i ] = ' a ' ; p ++ ; if ( p == k ) break ; } } if ( p < k ) { for ( int i = n - 1 ; i >= 0 ; i -- ) if ( str [ i ] == ' a ' ) { str2 [ i ] = ' b ' ; p ++ ; if ( p == k ) break ; } } cout << str2 << endl ; } int main ( ) { string str = " pqrs " ; int n = str . length ( ) ; int k = 2 ; findString ( str , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, p, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
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 char_freq [ SIZE ] ; memset ( char_freq , 0 , sizeof ( char_freq ) ) ; 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 ++ ; else nc ++ ; char_freq [ ch - 97 ] ++ ; } if ( abs ( nv - nc ) >= 2 ) return " no ▁ such ▁ string " ; for ( int i = 0 ; i < SIZE ; i ++ ) { char ch = ( char ) ( i + 97 ) ; for ( int j = 1 ; j <= char_freq [ i ] ; j ++ ) { if ( isVowel ( ch ) ) vstr += ch ; else cstr += ch ; } } 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 = " aeroplane " ; cout << findAltStr ( str ) ; return 0 ; }

Index/key variables: SIZE, i
Accumulator variables: cstr, i, j, nc, nv, stdc, vstr
Iterator variables: i, j