dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calcScore ( string str ) { int score = 0 ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; ) { int chunkSize = 1 ; char currentChar = str [ i ++ ] ; while ( i < len && str [ i ] == currentChar ) { chunkSize ++ ; i ++ ; } if ( currentChar == '1' ) score += pow ( chunkSize , 2 ) ; else score -= pow ( chunkSize , 2 ) ; } return score ; } int main ( ) { string str = "11011" ; cout << calcScore ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: chunkSize, i, score, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubString ( string s , char c , int k ) { int leftCount = 0 , rightCount = 0 ; int left = 0 , right = 0 ; int freq = 0 ; int result = 0 , len = s . length ( ) ; while ( s [ left ] != c && left < len ) { left ++ ; leftCount ++ ; } right = left + 1 ; while ( freq != ( k - 1 ) && ( right - 1 ) < len ) { if ( s [ right ] == c ) freq ++ ; right ++ ; } while ( left < len && ( right - 1 ) < len ) { while ( s [ left ] != c && left < len ) { left ++ ; leftCount ++ ; } while ( right < len && s [ right ] != c ) { if ( s [ right ] == c ) freq ++ ; right ++ ; rightCount ++ ; } result = result + ( leftCount + 1 ) * ( rightCount + 1 ) ; freq = k - 1 ; leftCount = 0 ; rightCount = 0 ; left ++ ; right ++ ; } return result ; } int main ( ) { string s = " abada " ; char c = ' a ' ; int k = 2 ; cout << countSubString ( s , c , k ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: left, right
Accumulator variables: freq, left, leftCount, right, rightCount, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  4
int performQueries ( int l , int r , int prefix [ N ] [ 26 ] ) { l -- ; r -- ; bool flag = false ; int count = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int cnt = prefix [ r ] [ i ] ; if ( l > 0 ) cnt -= prefix [ l - 1 ] [ i ] ; if ( cnt % 2 == 1 ) { flag = true ; count += cnt - 1 ; } else count += cnt ; } if ( flag ) count += 1 ; return count ; } void preCalculate ( string s , int prefix [ N ] [ 26 ] ) { int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { prefix [ i ] [ s [ i ] - ' a ' ] ++ ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) prefix [ i ] [ j ] += prefix [ i - 1 ] [ j ] ; } } int main ( ) { string s = " amim " ; int prefix [ N ] [ 26 ] ; memset ( prefix , 0 , sizeof prefix ) ; preCalculate ( s , prefix ) ; int queries [ ] [ 2 ] = { { 1 , 4 } , { 3 , 4 } } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) { cout << performQueries ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , prefix ) << endl ; } return 0 ; }

Index/key variables: N, i, j, r
Accumulator variables: cnt, count, i, j, l, r, stdc
Iterator variables: i, j
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int NumOccurrences ( string arr [ ] , int n , string str , int L , int R ) { unordered_map < string , vector < int > > M ; for ( int i = 0 ; i < n ; i ++ ) { string temp = arr [ i ] ; auto it = M . find ( temp ) ; if ( it == M . end ( ) ) { vector < int > A ; A . push_back ( i + 1 ) ; M . insert ( make_pair ( temp , A ) ) ; } else { it -> second . push_back ( i + 1 ) ; } } auto it = M . find ( str ) ; if ( it == M . end ( ) ) return 0 ; vector < int > A = it -> second ; int y = upper_bound ( A . begin ( ) , A . end ( ) , R ) - A . begin ( ) ; int x = upper_bound ( A . begin ( ) , A . end ( ) , L - 1 ) - A . begin ( ) ; return ( y - x ) ; } int main ( ) { string arr [ ] = { " abc " , " abcabc " , " abc " } ; int n = sizeof ( arr ) / sizeof ( string ) ; int L = 1 ; int R = 3 ; string str = " abc " ; cout << NumOccurrences ( arr , n , str , L , R ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isValid ( string str , int n ) { if ( ! ( ( str [ 0 ] >= ' a ' && str [ 0 ] <= ' z ' ) || ( str [ 0 ] >= ' A ' && str [ 0 ] <= ' Z ' ) str [ 0 ] == ' _ ' ) ) return false ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( ! ( ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) || ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) || ( str [ i ] >= '0' && str [ i ] <= '9' ) str [ i ] == ' _ ' ) ) return false ; } return true ; } int main ( ) { string str = " _ geeks123" ; int n = str . length ( ) ; if ( isValid ( str , n ) ) cout << " Valid " ; else cout << " Invalid " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std ; bool check ( string s , int l ) { vector < int > pos ; for ( int i = 0 ; i < l ; i ++ ) { if ( s [ i ] == '1' ) pos . push_back ( i ) ; } int t = pos . size ( ) ; for ( int i = 1 ; i < t ; i ++ ) { if ( ( pos [ i ] - pos [ i - 1 ] ) != ( pos [ 1 ] - pos [ 0 ] ) ) return false ; } return true ; } int main ( ) { string s = "100010001000" ; int l = s . length ( ) ; if ( check ( s , l ) ) 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 ; string FirstAndLast ( string str ) { string ch = str ; for ( int i = 0 ; i < ch . length ( ) ; i ++ ) { int k = i ; while ( i < ch . length ( ) && ch [ i ] != ' ▁ ' ) i ++ ; ch [ k ] = ( char ) ( ch [ k ] >= ' a ' && ch [ k ] <= ' z ' ? ( ( int ) ch [ k ] - 32 ) : ( int ) ch [ k ] ) ; ch [ i - 1 ] = ( char ) ( ch [ i - 1 ] >= ' a ' && ch [ i - 1 ] <= ' z ' ? ( ( int ) ch [ i - 1 ] - 32 ) : ( int ) ch [ i - 1 ] ) ; } return ch ; } int main ( ) { string str = " Geeks ▁ for ▁ Geeks " ; cout << str << " STRNEWLINE " ; cout << FirstAndLast ( str ) ; }

Index/key variables: i, k
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findM ( string s , int x ) { int cnt = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] - '0' != x ) cnt ++ ; } return cnt ; } int main ( ) { string s = "3662123" ; int x = 6 ; cout << findM ( s , x ) ; return 0 ; }

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

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > compute_lps ( string s ) { int n = s . size ( ) ; vector < int > lps ( n ) ; int len = 0 ; lps [ 0 ] = 0 ; int i = 1 ; while ( i < n ) { if ( s [ i ] == s [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) len = lps [ len - 1 ] ; else { lps [ i ] = 0 ; i ++ ; } } } return lps ; } void Longestsubstring ( string s ) { vector < int > lps = compute_lps ( s ) ; int n = s . size ( ) ; if ( lps [ n - 1 ] == 0 ) { cout << -1 ; return ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( lps [ i ] == lps [ n - 1 ] ) { cout << s . substr ( 0 , lps [ i ] ) ; return ; } } if ( lps [ lps [ n - 1 ] - 1 ] == 0 ) cout << -1 ; else cout << s . substr ( 0 , lps [ lps [ n - 1 ] - 1 ] ) ; } int main ( ) { string s = " fixprefixsuffix " ; Longestsubstring ( s ) ; return 0 ; }

Index/key variables: i, len
Accumulator variables: i, len, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  64
int getBitmask ( string s ) { int temp = 0 ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( s [ j ] == ' s ' ) { temp = temp | ( 1 ) ; } else if ( s [ j ] == ' t ' ) { temp = temp | ( 2 ) ; } else if ( s [ j ] == ' r ' ) { temp = temp | ( 4 ) ; } else if ( s [ j ] == ' i ' ) { temp = temp | ( 8 ) ; } else if ( s [ j ] == ' n ' ) { temp = temp | ( 16 ) ; } else if ( s [ j ] == ' g ' ) { temp = temp | ( 32 ) ; } } return temp ; } int countPairs ( string arr [ ] , int n ) { int bitMask [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) bitMask [ getBitmask ( arr [ i ] ) ] ++ ; int cnt = 0 ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = i ; j < MAX ; j ++ ) { if ( ( i j ) == ( MAX - 1 ) ) { if ( i == j ) cnt += ( ( bitMask [ i ] * bitMask [ i ] - 1 ) / 2 ) ; else cnt += ( bitMask [ i ] * bitMask [ j ] ) ; } } } return cnt ; } int main ( ) { string arr [ ] = { " strrr " , " string " , " gstrin " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairs ( arr , n ) ; return 0 ; }

Index/key variables: MAX, i, j
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countOcc ( string s ) { int cnt = 0 ; for ( int i = 0 ; i < s . length ( ) - 3 ; i ++ ) { int c = 0 , l = 0 , a = 0 , p = 0 ; for ( int j = i ; j < i + 4 ; j ++ ) { switch ( s [ j ] ) { case ' c ' : c ++ ; break ; case ' l ' : l ++ ; break ; case ' a ' : a ++ ; break ; case ' p ' : p ++ ; break ; } } if ( c == 1 && l == 1 && a == 1 && p == 1 ) cnt ++ ; } return cnt ; } int main ( ) { string s = " clapc " ; transform ( s . begin ( ) , s . end ( ) , s . begin ( ) , :: tolower ) ; cout << ( countOcc ( s ) ) ; }

Index/key variables: j
Accumulator variables: a, c, cnt, i, j, l, p, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int pairCount ( map < string , int > & d ) { int sum = 0 ; for ( auto i : d ) sum += ( i . second * ( i . second - 1 ) ) / 2 ; return sum ; } int difference ( vector < string > & array , int m ) { map < string , int > changed , same ; for ( auto s : array ) { same [ s ] ++ ; for ( int i = 0 ; i < m ; i ++ ) { changed [ t ] ++ ; } } return pairCount ( changed ) - pairCount ( same ) * m ; } int main ( ) { int n = 3 , m = 3 ; vector < string > array = { " abc " , " abd " , " bbd " } ; cout << difference ( array , m ) << endl ; return 0 ; }

Index/key variables: s, t
Accumulator variables: i, stdc, sum
Iterator variables: i, s
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateWays ( string s , int n , int l , int r ) { int freq [ 26 ] ; memset ( freq , 0 , sizeof freq ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < l i > r ) freq [ s [ i ] - ' a ' ] ++ ; } int ways = 1 ; for ( int i = l ; i <= r ; i ++ ) { if ( freq [ s [ i ] - ' a ' ] ) { ways = ways * freq [ s [ i ] - ' a ' ] ; freq [ s [ i ] - ' a ' ] -- ; } else { ways = 0 ; break ; } } return ways ; } int main ( ) { string s = " cabcaab " ; int n = s . length ( ) ; int l = 1 , r = 3 ; cout << calculateWays ( s , n , l , r ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <cstdlib>
#include <iostream>
using namespace std ; char findKthChar ( string s , int k ) { int len = s . length ( ) ; int i = 0 ; int total_len = 0 ; while ( i < len ) { if ( isalpha ( s [ i ] ) ) { total_len ++ ; if ( total_len == k ) return s [ i ] ; i ++ ; } else { int n = 0 ; while ( i < len && ! isalpha ( s [ i ] ) ) { n = n * 10 + ( s [ i ] - '0' ) ; i ++ ; } int next_total_len = total_len * n ; if ( k <= next_total_len ) { int pos = k % total_len ; if ( ! pos ) { pos = total_len ; } return findKthChar ( s , pos ) ; } else { total_len = next_total_len ; } } } return -1 ; } int main ( ) { string s = " ab2c3" ; int k = 5 ; cout << findKthChar ( s , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, total_len
C++ program:
#include <bits/stdc++.h>
#include <math.h>
using namespace std ; bool check_char ( char * st , char ch ) { int l = strlen ( st ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( st [ i ] == ch ) return true ; } return false ; } char find_avg ( char * st ) { int i , sm = 0 ; int l = strlen ( st ) ; char ch ; for ( i = 0 ; i < l ; i ++ ) { ch = st [ i ] ; sm = sm + ( int ) ( ch ) ; } int avg = ( int ) ( floor ( sm / l ) ) ; return ( ( char ) ( avg ) ) ; } int main ( ) { char st [ ] = " ag23sdfa " ; char ch = find_avg ( st ) ; cout << ch << endl ; if ( check_char ( st , ch ) == true ) 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 ; void asciiToSentence ( string str , int len ) { int num = 0 ; for ( int i = 0 ; i < len ; i ++ ) { num = num * 10 + ( str [ i ] - '0' ) ; if ( num >= 32 && num <= 122 ) { char ch = ( char ) num ; cout << ch ; num = 0 ; } } } int main ( ) { string str = "7110110110711510211111471101101107115" ; int len = str . length ( ) ; asciiToSentence ( str , len ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countDistinctCode ( string str ) { set < string > codes ; for ( int i = 0 ; i < str . length ( ) - 1 ; i ++ ) codes . insert ( str . substr ( i , 2 ) ) ; return codes . size ( ) ; } int main ( ) { string str = " UPUP " ; cout << countDistinctCode ( str ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int arr [ ] = { 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 1 , 2 , 3 , 4 } ; int countKeyPressed ( string str , int len ) { int count = 0 ; for ( int i = 0 ; i < len ; i ++ ) count = count + arr [ str [ i ] - ' a ' ] ; return count ; } int main ( ) { string str = " abcdef " ; int len = str . length ( ) ; cout << countKeyPressed ( str , len ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isReverseEqual ( string s1 , string s2 ) { if ( s1 . length ( ) != s2 . length ( ) ) return false ; int len = s1 . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) if ( s1 [ i ] != s2 [ len - i - 1 ] ) return false ; return true ; } string getWord ( string str [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( isReverseEqual ( str [ i ] , str [ j ] ) ) return str [ i ] ; return " - 1" ; } int main ( ) { string str [ ] = { " geeks " , " for " , " skeeg " } ; cout << ( getWord ( str , 3 ) ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPrefix ( string str , int len , int i , int k ) { if ( i + k > len ) return false ; for ( int j = 0 ; j < k ; j ++ ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; } return true ; } bool isKPeriodic ( string str , int len , int k ) { for ( int i = k ; i < len ; i += k ) if ( ! isPrefix ( str , len , i , k ) ) return false ; return true ; } int main ( ) { string str = " geeksgeeks " ; int len = str . length ( ) ; int k = 5 ; if ( isKPeriodic ( str , len , k ) ) cout << ( " Yes " ) ; else cout << ( " No " ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minLettersNeeded ( int n ) { if ( n % 26 == 0 ) return ( n / 26 ) ; else return ( ( n / 26 ) + 1 ) ; } int main ( ) { int n = 52 ; cout << minLettersNeeded ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findMaxLenEven ( string str ) { int n = str . length ( ) ; int i = 0 ; int currlen = 0 ; int maxlen = 0 ; int st = -1 ; while ( i < n ) { if ( str [ i ] == ' ▁ ' ) { if ( currlen % 2 == 0 ) { if ( maxlen < currlen ) { maxlen = currlen ; st = i - currlen ; } } currlen = 0 ; } else { currlen ++ ; } i ++ ; } if ( currlen % 2 == 0 ) { if ( maxlen < currlen ) { maxlen = currlen ; st = i - currlen ; } } if ( st == -1 ) return " - 1" ; return str . substr ( st , maxlen ) ; } int main ( ) { string str = " this ▁ is ▁ a ▁ test ▁ string " ; cout << findMaxLenEven ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: currlen, i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findMinLenStr ( string str , int k ) { int n = str . length ( ) ; int st = 0 ; int end = 0 ; int cnt [ 26 ] ; memset ( cnt , 0 , sizeof ( cnt ) ) ; int distEle = 0 ; int currlen ; int minlen = n ; int startInd = -1 ; while ( end < n ) { cnt [ str [ end ] - ' a ' ] ++ ; if ( cnt [ str [ end ] - ' a ' ] == 1 ) distEle ++ ; if ( distEle > k ) { while ( st < end && distEle > k ) { if ( cnt [ str [ st ] - ' a ' ] == 1 ) distEle -- ; cnt [ str [ st ] - ' a ' ] -- ; st ++ ; } } if ( distEle == k ) { while ( st < end && cnt [ str [ st ] - ' a ' ] > 1 ) { cnt [ str [ st ] - ' a ' ] -- ; st ++ ; } currlen = end - st + 1 ; if ( currlen < minlen ) { minlen = currlen ; startInd = st ; } } end ++ ; } return str . substr ( startInd , minlen ) ; } int main ( ) { string str = " efecfefd " ; int k = 4 ; cout << findMinLenStr ( str , k ) ; return 0 ; }

Index/key variables: end, st
Accumulator variables: distEle, end, st, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minReplacement ( string s , int len ) { int ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( i % 2 == 0 && s [ i ] == '1' ) ans ++ ; if ( i % 2 == 1 && s [ i ] == '0' ) ans ++ ; } return min ( ans , len - ans ) ; } int main ( ) { string s = "1100" ; int len = s . size ( ) ; cout << minReplacement ( s , len ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int substrDeletion ( string str , int len ) { int count0 = 0 , count1 = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) count0 ++ ; else count1 ++ ; } return min ( count0 , count1 ) ; } int main ( ) { string str = "010" ; int len = str . length ( ) ; cout << substrDeletion ( str , len ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count0, count1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string groupCharacters ( string s , int len ) { string temp = " " ; for ( int i = 0 ; i < len ; i ++ ) if ( s [ i ] != ' ▁ ' ) temp = temp + s [ i ] ; len = temp . length ( ) ; string ans = " " ; int i = 0 ; while ( i < len ) { if ( int ( temp [ i ] ) >= int ( ' A ' ) && int ( temp [ i ] ) <= int ( ' Z ' ) ) { while ( i < len && int ( temp [ i ] ) >= int ( ' A ' ) && int ( temp [ i ] ) <= int ( ' Z ' ) ) { ans = ans + temp [ i ] ; i ++ ; } ans = ans + " ▁ " ; } else if ( int ( temp [ i ] ) >= int ( '0' ) && int ( temp [ i ] ) <= int ( '9' ) ) { while ( i < len && int ( temp [ i ] ) >= int ( '0' ) && int ( temp [ i ] ) <= int ( '9' ) ) { ans = ans + temp [ i ] ; i ++ ; } ans = ans + " ▁ " ; } else { while ( i < len && int ( temp [ i ] ) >= int ( ' * ' ) && int ( temp [ i ] ) <= int ( ' / ' ) ) { ans = ans + temp [ i ] ; i ++ ; } ans = ans + " ▁ " ; } } return ans ; } int main ( ) { string s = "34FTG234 + ▁ + - ▁ * " ; int len = s . length ( ) ; cout << groupCharacters ( s , len ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Preprocess ( string A , string B ) { int n = A . size ( ) ; int ans = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { map < char , int > mp ; mp [ A [ i ] ] ++ ; mp [ A [ n - i - 1 ] ] ++ ; mp [ B [ i ] ] ++ ; mp [ B [ n - i - 1 ] ] ++ ; int sz = mp . size ( ) ; if ( sz == 4 ) ans += 2 ; else if ( sz == 3 ) ans += 1 + ( A [ i ] == A [ n - i - 1 ] ) ; else if ( sz == 2 ) ans += mp [ A [ i ] ] != 2 ; } if ( n % 2 == 1 && A [ n / 2 ] != B [ n / 2 ] ) ans ++ ; return ans ; } int main ( ) { string A = " abacaba " , B = " bacabaa " ; cout << Preprocess ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string leastLexiString ( string s ) { if ( s . size ( ) & 1 ) return s ; string x = leastLexiString ( s . substr ( 0 , s . size ( ) / 2 ) ) ; string y = leastLexiString ( s . substr ( s . size ( ) / 2 ) ) ; return min ( x + y , y + x ) ; } bool areEquivalent ( string a , string b ) { return ( leastLexiString ( a ) == leastLexiString ( b ) ) ; } int main ( ) { string a = " aaba " ; string b = " abaa " ; if ( areEquivalent ( a , b ) ) cout << " YES " << endl ; else cout << " NO " << endl ; a = " aabb " ; b = " abab " ; if ( areEquivalent ( a , b ) ) cout << " YES " << endl ; else cout << " NO " << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char c ) { if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) return true ; return false ; } bool checkPossibility ( string s1 , string s2 ) { int l1 = s1 . length ( ) ; int l2 = s2 . length ( ) ; if ( l1 != l2 ) return false ; for ( int i = 0 ; i < l1 ; i ++ ) { if ( isVowel ( s1 [ i ] ) && isVowel ( s2 [ i ] ) ) continue ; else if ( ! ( isVowel ( s1 [ i ] ) ) && ! ( isVowel ( s2 [ i ] ) ) ) continue ; else return false ; } return true ; } int main ( ) { string S1 = " abcgle " , S2 = " ezggli " ; if ( checkPossibility ( 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 ; void generateString ( int A , int B ) { string rt ; while ( 0 < A 0 < B ) { if ( A < B ) { if ( 0 < B -- ) rt . push_back ( ' b ' ) ; if ( 0 < B -- ) rt . push_back ( ' b ' ) ; if ( 0 < A -- ) rt . push_back ( ' a ' ) ; } else if ( B < A ) { if ( 0 < A -- ) rt . push_back ( ' a ' ) ; if ( 0 < A -- ) rt . push_back ( ' a ' ) ; if ( 0 < B -- ) rt . push_back ( ' b ' ) ; } else { if ( 0 < A -- ) rt . push_back ( ' a ' ) ; if ( 0 < B -- ) rt . push_back ( ' b ' ) ; } } cout << rt ; } int main ( ) { int A = 2 , B = 6 ; generateString ( A , B ) ; return 0 ; }

Accumulator variables: A, B, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string getSubSeq ( string s , int n ) { string res = " " ; int cr = 0 ; while ( cr < n ) { char mx = s [ cr ] ; for ( int i = cr + 1 ; i < n ; i ++ ) mx = max ( mx , s [ i ] ) ; int lst = cr ; for ( int i = cr ; i < n ; i ++ ) if ( s [ i ] == mx ) { res += s [ i ] ; lst = i ; } cr = lst + 1 ; } return res ; } int main ( ) { string s = " geeksforgeeks " ; int n = s . length ( ) ; cout << getSubSeq ( s , n ) ; }

Index/key variables: cr, i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isValid ( string str ) { int k = 0 ; string operands [ 5 ] = " " ; char operators [ 4 ] ; long ans = 0 , ans1 = 0 , ans2 = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] != ' + ' && str [ i ] != ' = ' && str [ i ] != ' - ' ) operands [ k ] += str [ i ] ; else { operators [ k ] = str [ i ] ; if ( k == 1 ) { if ( operators [ k - 1 ] == ' + ' ) ans += stol ( operands [ k - 1 ] ) + stol ( operands [ k ] ) ; if ( operators [ k - 1 ] == ' - ' ) ans += stol ( operands [ k - 1 ] ) - stol ( operands [ k ] ) ; } if ( k == 2 ) { if ( operators [ k - 1 ] == ' + ' ) ans1 += ans + stol ( operands [ k ] ) ; if ( operators [ k - 1 ] == ' - ' ) ans1 -= ans - stol ( operands [ k ] ) ; } if ( k == 3 ) { if ( operators [ k - 1 ] == ' + ' ) ans2 += ans1 + stol ( operands [ k ] ) ; if ( operators [ k - 1 ] == ' - ' ) ans2 -= ans1 - stol ( operands [ k ] ) ; } k ++ ; } } if ( ans2 == stol ( operands [ 4 ] ) ) return true ; else return false ; } int main ( ) { string str = "2 + 5 + 3 + 1 = 11" ; if ( isValid ( str ) ) cout << " Valid " ; else cout << " Invalid " ; return 0 ; }

Index/key variables: i, k
Accumulator variables: ans, ans1, ans2, i, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMinimalReplacements ( string s ) { int n = s . length ( ) ; int mini = INT_MAX ; string dup = "012" ; do { int dif = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( s [ i ] != dup [ i % 3 ] ) dif ++ ; mini = min ( mini , dif ) ; } while ( next_permutation ( dup . begin ( ) , dup . end ( ) ) ) ; return mini ; } int main ( ) { string s = "2101200" ; cout << countMinimalReplacements ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: dif, i, stdc
Iterator variables: i