dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count ( string S , int X , int Y ) { int N = S . length ( ) ; int temp_x = 0 , temp_y = 0 ; int count = 0 ; set < pair < int , int > > s ; s . insert ( { X , Y } ) ; for ( int i = 0 ; i < N ; i ++ ) { temp_x = X ; temp_y = Y ; if ( S [ i ] == ' U ' ) { X ++ ; } else if ( S [ i ] == ' D ' ) { X -- ; } else if ( S [ i ] == ' R ' ) { Y ++ ; } else { Y -- ; } if ( s . find ( { temp_x + X , temp_y + Y } ) != s . end ( ) ) { count ++ ; } else { s . insert ( { temp_x + X , temp_y + Y } ) ; } } return count ; } int main ( ) { string S = " RDDUDL " ; int X = 0 , Y = 0 ; cout << count ( S , X , Y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: X, Y, count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countTotalFrequencies ( string S1 , string S2 ) { set < char > bset ; for ( auto x : S1 ) bset . insert ( x ) ; int count = 0 ; for ( auto x : S2 ) { if ( bset . find ( x ) != bset . end ( ) ) count += 1 ; } cout << count << endl ; } int main ( ) { string S1 = " geEksFOR " ; string S2 = " GeEksforgeEKS " ; countTotalFrequencies ( S1 , S2 ) ; }

Accumulator variables: count, stdc
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nonDecreasing ( string s ) { int size = s . length ( ) ; char c = ' a ' ; for ( int i = 0 ; i < size ; i ++ ) { if ( s [ i ] == ' ? ' ) { continue ; } else if ( ( s [ i ] != ' ? ' ) && ( s [ i ] < c ) ) { return 0 ; } else { c = s [ i ] ; } } return 1 ; } int main ( ) { string S = " abb ? xy ? " ; if ( nonDecreasing ( S ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int min_length ( string str ) { int n = str . length ( ) ; int total_zeros = 0 ; int total_ones = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '0' ) total_zeros ++ ; else total_ones ++ ; } int ans = min ( total_zeros , total_ones ) ; int cur_zeros = 0 , cur_ones = 0 ; for ( char x : str ) { if ( x == '0' ) cur_zeros ++ ; else cur_ones ++ ; ans = min ( ans , cur_ones + ( total_zeros - cur_zeros ) ) ; } cout << ans ; } int main ( ) { string str = "10011" ; min_length ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cur_ones, cur_zeros, i, stdc, total_ones, total_zeros
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void kFreqWords ( string S , int K ) { string temp = " " ; vector < string > l ; for ( auto x : S ) { if ( x == ' ▁ ' ) { l . push_back ( temp ) ; temp = " " ; } else temp += x ; } for ( auto x : l ) { if ( count ( l . begin ( ) , l . end ( ) , x ) == K ) { cout << x << endl ; remove ( l . begin ( ) , l . end ( ) , x ) ; } } } int main ( ) { string S = " banana ▁ is ▁ in ▁ yellow ▁ and ▁ sun ▁ flower ▁ is ▁ also ▁ in ▁ yellow ▁ " ; int K = 2 ; kFreqWords ( S , K ) ; }

Accumulator variables: stdc, temp
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; string make_palindrome ( string S1 , string S2 , string S3 ) { int maskA = 0 , maskC = 0 ; for ( char i : S1 ) maskA |= ( 1 << ( i - ' a ' ) ) ; for ( char i : S3 ) maskC |= ( 1 << ( i - ' a ' ) ) ; if ( ( maskA & maskC ) > 0 ) return " YES " ; return " NO " ; } int main ( ) { string S1 = " adcb " , S2 = " bcdb " , S3 = " abe " ; cout << make_palindrome ( S1 , S2 , S3 ) ; }

Accumulator variables: maskA, maskC, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define SIZE  26
bool longHelper ( int freq1 [ ] , int freq2 [ ] ) { for ( int i = 0 ; i < SIZE ; ++ i ) { if ( freq1 [ i ] != freq2 [ i ] ) { return false ; } } return true ; } int longCommomPrefixAnagram ( string s1 , string s2 , int n1 , int n2 ) { int freq1 [ 26 ] = { 0 } ; int freq2 [ 26 ] = { 0 } ; int ans = 0 ; int mini_len = min ( n1 , n2 ) ; for ( int i = 0 ; i < mini_len ; ++ i ) { freq1 [ s1 [ i ] - ' a ' ] ++ ; freq2 [ s2 [ i ] - ' a ' ] ++ ; if ( longHelper ( freq1 , freq2 ) ) { ans = i + 1 ; } } cout << ans ; } int main ( ) { string str1 = " abaabcdezzwer " ; string str2 = " caaabbttyh " ; int N = str1 . length ( ) ; int M = str2 . length ( ) ; longCommomPrefixAnagram ( str1 , str2 , N , M ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void findRank ( string s ) { int N = s . size ( ) ; string bin ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '0' ) bin += "0" ; else bin += "1" ; } long long X = 1ll << N ; long long res = 0 , val = 1 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( bin [ i ] == '1' ) res += ( val ) ; val *= 2ll ; } long long Y = res ; long ans = X + Y - 1 ; cout << ans ; } int main ( ) { string S = "001" ; findRank ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: bin, i, res, val
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int GCD ( int lena , int lenb ) { if ( lena == 0 ) return lenb ; if ( lenb == 0 ) return lena ; if ( lena == lenb ) return lena ; if ( lena > lenb ) return GCD ( lena - lenb , lenb ) ; return GCD ( lena , lenb - lena ) ; } string StringGCD ( string a , string b ) { int gcd = GCD ( a . size ( ) , b . size ( ) ) ; if ( a . substr ( 0 , gcd ) == b . substr ( 0 , gcd ) ) { int x = ( ( int ) b . size ( ) / gcd ) ; int y = ( ( int ) a . size ( ) / gcd ) ; string r = " " , s = " " ; while ( x -- ) s += a ; while ( y -- ) r += b ; if ( s == r ) return a . substr ( 0 , gcd ) ; } return " - 1" ; } int main ( ) { string a = " geeksgeeks " ; string b = " geeks " ; cout << ( StringGCD ( a , b ) ) ; }

Accumulator variables: r, s, stdc, x, y
C++ program:
#include <iostream>
#include <stack>
using namespace std ; long long scoreOfParentheses ( string S ) { stack < string > s ; int i = 0 ; long long ans = 0 ; while ( i < S . length ( ) ) { if ( S [ i ] == ' ( ' ) s . push ( " ( " ) ; else { if ( s . top ( ) == " ( " ) { s . pop ( ) ; s . push ( "1" ) ; } else { long long count = 0 ; while ( s . top ( ) != " ( " ) { count += stoi ( s . top ( ) ) ; s . pop ( ) ; } s . pop ( ) ; s . push ( to_string ( 2 * count ) ) ; } } i ++ ; } while ( ! s . empty ( ) ) { ans += stoi ( s . top ( ) ) ; s . pop ( ) ; } return ans ; } int main ( ) { string S1 = " ( ( ) ( ( ) ) ) " ; cout << scoreOfParentheses ( S1 ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, count, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countMinMoves ( string str ) { int n = str . size ( ) ; int a [ n ] = { 0 } ; int j , ans = 0 , i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ) ' ) { a [ i ] += sum - 1 ; } else { a [ i ] += sum + 1 ; } sum = a [ i ] ; } if ( sum == 0 ) { i = 1 ; while ( i < n ) { j = i - 1 ; while ( i < n && a [ i ] != 0 ) i ++ ; if ( i < n && a [ i - 1 ] < 0 ) { ans += i - j ; if ( j == 0 ) ans ++ ; } i ++ ; } cout << ans << endl ; } else cout << " - 1 STRNEWLINE " ; } int main ( ) { string str = " ) ( ( ) " ; countMinMoves ( str ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canBeBalanced ( string sequence ) { if ( sequence . size ( ) % 2 ) return false ; stack < char > stack_ , stack2_ ; int countOpen = 0 , countClosed = 0 ; int countSymbol = 0 ; for ( int i = 0 ; i < sequence . size ( ) ; i ++ ) { if ( sequence [ i ] == ' ) ' ) { countClosed ++ ; if ( stack_ . empty ( ) ) { return false ; } else { stack_ . pop ( ) ; } } else { if ( sequence [ i ] == ' $ ' ) { countSymbol ++ ; } else { countOpen ++ ; } stack_ . push ( sequence [ i ] ) ; } } for ( int i = sequence . size ( ) - 1 ; i >= 0 ; i -- ) { if ( sequence [ i ] == ' ( ' ) { if ( stack2_ . empty ( ) ) { return false ; } else { stack2_ . pop ( ) ; } } else { stack2_ . push ( sequence [ i ] ) ; } } int extra = abs ( countClosed - countOpen ) ; if ( countSymbol < extra ) { return false ; } else { countSymbol -= extra ; if ( countSymbol % 2 == 0 ) { return true ; } } return false ; } int main ( ) { string S = " ( ) ( $ " ; if ( canBeBalanced ( S ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Index/key variables: i
Accumulator variables: countClosed, countOpen, countSymbol, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxDiffFreq ( vector < pair < int , int > > queries , string S ) { int N = S . size ( ) ; int Q = queries . size ( ) ; for ( int i = 0 ; i < Q ; ++ i ) { int l = queries [ i ] . first - 1 ; int r = queries [ i ] . second - 1 ; int freq [ 26 ] = { 0 } ; for ( int j = l ; j <= r ; j ++ ) { freq [ S [ j ] - ' a ' ] ++ ; } int mx = 0 ; int mn = 99999999 ; for ( int j = 0 ; j < 26 ; j ++ ) { mx = max ( mx , freq [ j ] ) ; if ( freq [ j ] ) mn = min ( mn , freq [ j ] ) ; } cout << mx - mn << endl ; } } int main ( ) { string S = " abaabac " ; vector < pair < int , int > > queries { { 2 , 6 } , { 1 , 7 } } ; maxDiffFreq ( queries , S ) ; }

Index/key variables: i, j
Accumulator variables: j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubstrings ( string str ) { map < pair < pair < int , int > , pair < int , int > > , int > mp ; mp [ { { 0 , 0 } , { 0 , 0 } } ] ++ ; int p = 0 ; int q = 0 ; int r = 0 ; int s = 0 ; int cntSub = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == ' a ' ) { p ++ ; int Y = min ( min ( s , r ) , min ( p , q ) ) ; p -= Y ; q -= Y ; r -= Y ; s -= Y ; } else if ( str [ i ] == ' b ' ) { q ++ ; int Y = min ( min ( p , q ) , min ( r , s ) ) ; p -= Y ; q -= Y ; r -= Y ; s -= Y ; } else if ( str [ i ] == ' c ' ) { r ++ ; int Y = min ( min ( p , q ) , min ( r , s ) ) ; p -= Y ; q -= Y ; r -= Y ; s -= Y ; } else if ( str [ i ] == ' d ' ) { s ++ ; int Y = min ( min ( p , q ) , min ( r , s ) ) ; p -= Y ; q -= Y ; r -= Y ; s -= Y ; } mp [ { { p , q } , { r , s } } ] ++ ; } for ( auto & e : mp ) { int freq = e . second ; cntSub += ( freq ) * ( freq - 1 ) / 2 ; } return cntSub ; } int main ( ) { string str = " abcdefg " ; cout << countSubstrings ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cntSub, i, p, q, r, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct TrieNode { TrieNode * Trie [ 256 ] ; bool isEnd ; TrieNode ( ) { for ( int i = 0 ; i < 256 ; i ++ ) { Trie [ i ] = NULL ; } isEnd = false ; } } ; void InsertTrie ( TrieNode * root , string s ) { TrieNode * temp = root ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( temp -> Trie [ s [ i ] ] == NULL ) { temp -> Trie [ s [ i ] ] = new TrieNode ( ) ; } temp = temp -> Trie [ s [ i ] ] ; } temp -> isEnd = true ; } void printSuggestions ( TrieNode * root , string res ) { if ( root -> isEnd == true ) { cout << res << " ▁ " ; } for ( int i = 0 ; i < 256 ; i ++ ) { if ( root -> Trie [ i ] != NULL ) { res . push_back ( i ) ; printSuggestions ( root -> Trie [ i ] , res ) ; res . pop_back ( ) ; } } } bool checkPresent ( TrieNode * root , string key ) { for ( int i = 0 ; i < key . length ( ) ; i ++ ) { if ( root -> Trie [ key [ i ] ] == NULL ) { printSuggestions ( root , key . substr ( 0 , i ) ) ; return false ; } root = root -> Trie [ key [ i ] ] ; } if ( root -> isEnd == true ) { return true ; } printSuggestions ( root , key ) ; return false ; } int main ( ) { vector < string > str = { " gee " , " geeks " , " ape " , " apple " , " geeksforgeeks " } ; string key = " geek " ; TrieNode * root = new TrieNode ( ) ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { InsertTrie ( root , str [ i ] ) ; } if ( checkPresent ( root , key ) ) { cout << " YES " ; } return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: isEnd
Class/struct names: TrieNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countStrings ( string S , vector < string > & list ) { unordered_set < char > valid ; for ( auto x : S ) { valid . insert ( x ) ; } int cnt = 0 ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int j = 0 ; for ( j = 0 ; j < list [ i ] . size ( ) ; j ++ ) { if ( valid . count ( list [ i ] [ j ] ) ) continue ; else break ; } if ( j == list [ i ] . size ( ) ) cnt ++ ; } return cnt ; } int main ( ) { vector < string > arr = { " ab " , " aab " , " abaaaa " , " bbd " } ; string S = " ab " ; cout << countStrings ( S , arr ) << endl ; }

Index/key variables: i, j
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minLength ( string str , int N , string K , int M ) { stack < char > stackOfChar ; for ( int i = 0 ; i < N ; i ++ ) { stackOfChar . push ( str [ i ] ) ; if ( stackOfChar . size ( ) >= M ) { string l = " " ; for ( int j = M - 1 ; j >= 0 ; j -- ) { if ( K [ j ] != stackOfChar . top ( ) ) { int f = 0 ; while ( f != l . size ( ) ) { stackOfChar . push ( l [ f ] ) ; f ++ ; } break ; } else { l = stackOfChar . top ( ) + l ; stackOfChar . pop ( ) ; } } } } return stackOfChar . size ( ) ; } int main ( ) { string S1 = " fffoxoxoxfxo " ; string S2 = " fox " ; int N = S1 . length ( ) ; int M = S2 . length ( ) ; cout << minLength ( S1 , N , S2 , M ) ; return 0 ; }

Index/key variables: f, i, j
Accumulator variables: f, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void palindrome_prod ( string N ) { vector < int > palindrome_list ; for ( int i = 101 ; i < 1000 ; i ++ ) { for ( int j = 121 ; j < 1000 ; j += ( i % 11 == 0 ) ? 1 : 11 ) { int n = i * j ; string x = to_string ( n ) ; string y = x ; reverse ( y . begin ( ) , y . end ( ) ) ; if ( x == y ) { if ( n < stoi ( N ) ) { palindrome_list . push_back ( i * j ) ; } } } } cout << ( * max_element ( palindrome_list . begin ( ) , palindrome_list . end ( ) ) ) ; } int main ( ) { string N = "101110" ; palindrome_prod ( N ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isEqualStrings ( string arr [ ] , int N ) { int M = arr [ 0 ] . length ( ) ; int cntFreq [ 256 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { cntFreq [ arr [ i ] [ j ] - ' a ' ] ++ ; } } for ( int i = 0 ; i < 256 ; i ++ ) { if ( cntFreq [ i ] % N != 0 ) { return false ; } } return true ; } int main ( ) { string arr [ ] = { " aab " , " bbc " , " cca " } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( isEqualStrings ( arr , N ) ) { cout << " YES " ; } else { cout << " NO " ; } return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void PrintStack ( stack < char > s ) { if ( s . empty ( ) ) return ; char x = s . top ( ) ; s . pop ( ) ; PrintStack ( s ) ; cout << x ; s . push ( x ) ; } void minString ( string s ) { stack < char > Stack ; Stack . push ( s [ 0 ] ) ; for ( int i = 1 ; i < s . size ( ) ; i ++ ) { if ( Stack . empty ( ) ) { Stack . push ( s [ i ] ) ; } else { if ( Stack . top ( ) == s [ i ] ) { Stack . pop ( ) ; } else { Stack . push ( s [ i ] ) ; } } } PrintStack ( Stack ) ; } int main ( ) { string str = "101001" ; minString ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; double count_of_accident ( string a , string b ) { int n = a . size ( ) , m = b . size ( ) ; if ( n > m ) return ( m * ( m + 1 ) ) / 2 ; else return ( n * ( n + 1 ) ) / 2 + ( m - n ) * n ; } double count_of_collision ( string a , string b ) { int n = a . size ( ) , m = b . size ( ) ; int answer = 0 ; int count_of_truck_in_lane_b = 0 ; for ( int i = 0 ; i < m ; i ++ ) if ( b [ i ] == ' T ' ) count_of_truck_in_lane_b ++ ; for ( int i = 0 ; i < n && i < m ; i ++ ) { if ( a [ i ] == ' T ' ) answer += count_of_truck_in_lane_b ; if ( b [ i ] == ' T ' ) count_of_truck_in_lane_b -- ; } return answer ; } double findProbability ( string a , string b ) { double total_outcome = count_of_accident ( a , b ) ; double favourable_outcome = count_of_collision ( a , b ) ; cout << favourable_outcome / total_outcome ; } int main ( ) { string S = " TCCBCTTB " , T = " BTCCBBTT " ; findProbability ( S , T ) ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, count_of_truck_in_lane_b, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } int main ( ) { int N = 3 ; int flag , k , m ; if ( ( N == 1 ) || ( N == 2 ) ) cout << 62 ; else m = 1000000000 + 7 ; if ( N % 2 == 0 ) { k = N / 2 ; flag = true ; } else { k = ( N - 1 ) / 2 ; flag = false ; } if ( flag != 0 ) { int a = power ( 62 , k , m ) ; cout << a ; } else { int a = power ( 62 , ( k + 1 ) , m ) ; cout << a ; } }

Accumulator variables: stdc
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lenOfLongestReqSubstr ( string s , int N ) { unordered_map < int , int > ind ; int mask = 0 ; ind [ 0 ] = -1 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int val = s [ i ] - '0' ; mask ^= ( 1 << val ) ; if ( ind . find ( mask ) != ind . end ( ) ) { ans = max ( ans , i - ind [ mask ] ) ; } else ind [ mask ] = i ; } return ans ; } int main ( ) { string s = "223015150" ; int N = s . length ( ) ; cout << lenOfLongestReqSubstr ( s , N ) ; return 0 ; }

Index/key variables: i, mask
Accumulator variables: i, mask, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int uniqueMorseRep ( vector < string > & arr ) { vector < string > morseCode = { " . - " , " - . . . " , " - . - . " , " - . . " , " . " , " . . - . " , " - - . " , " . . . . " , " . . " , " . - - - " , " - . - " , " . - . . " , " - - " , " - . " , " - - - " , " . - - . " , " - - . - " , " . - . " , " . . . " , " - " , " . . - " , " . . . - " , " . - - " , " - . . - " , " - . - - " , " - - . . " } ; set < string > st ; int N = arr . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { string temp = " " ; int M = arr [ i ] . length ( ) ; for ( int j = 0 ; j < M ; j ++ ) { temp += morseCode [ arr [ i ] [ j ] - ' a ' ] ; } st . insert ( temp ) ; } return st . size ( ) ; } int main ( ) { vector < string > arr = { " gig " , " zeg " , " gin " , " msn " } ; cout << uniqueMorseRep ( arr ) << endl ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, temp
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findFreq ( string str , int N ) { int freq [ 256 ] ; memset ( freq , 0 , sizeof ( freq ) ) ; int max = 0 ; char charMax = '0' ; for ( int i = 0 ; i < N ; i ++ ) { char ch = str [ i ] ; freq [ ch ] ++ ; if ( freq [ ch ] >= max ) { max = freq [ ch ] ; charMax = ch ; } cout << charMax << " - > " << max << endl ; } } int main ( ) { string str = " abbc " ; int N = str . size ( ) ; findFreq ( str , N ) ; }

Index/key variables: ch, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinCost ( string str , int pos ) { int n = str . length ( ) ; if ( pos >= n / 2 ) { reverse ( str . begin ( ) , str . end ( ) ) ; pos = n - pos - 1 ; } int left , right ; left = right = pos ; for ( int i = pos ; i >= 0 ; -- i ) { if ( str [ i ] != str [ n - i - 1 ] ) { left = i ; } } for ( int i = pos ; i < n / 2 ; ++ i ) { if ( str [ i ] != str [ n - i - 1 ] ) { right = i ; } } int ans = 0 ; for ( int i = left ; i <= right ; ++ i ) { if ( str [ i ] != str [ n - i - 1 ] ) ans += 1 ; } int dis = min ( ( 2 * ( pos - left ) + ( right - pos ) ) , ( 2 * ( right - pos ) + ( pos - left ) ) ) ; ans = ans + dis ; return ans ; } int main ( ) { string S = " bass " ; int P = 3 ; cout << findMinCost ( S , P ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCost ( string s , int n ) { int minValue = 100000000 ; for ( int i = 0 ; i <= 25 ; i ++ ) { int cnt = 0 ; for ( int j = 0 ; j < n ; j ++ ) { cnt += min ( abs ( i - ( s [ j ] - ' a ' ) ) , 26 - abs ( i - ( s [ j ] - ' a ' ) ) ) ; } minValue = min ( minValue , cnt ) ; } return minValue ; } int main ( ) { string str = " geeksforgeeks " ; int N = str . length ( ) ; cout << minCost ( str , N ) ; return 0 ; }

Index/key variables: j
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void max_len ( string s [ ] , int N , int M ) { unordered_set < string > set_str ; for ( int i = 0 ; i < N ; i ++ ) { set_str . insert ( s [ i ] ) ; } vector < string > left_ans , right_ans ; string mid ; for ( int i = 0 ; i < N ; i ++ ) { string t = s [ i ] ; reverse ( t . begin ( ) , t . end ( ) ) ; if ( t == s [ i ] ) { mid = t ; } else if ( set_str . find ( t ) != set_str . end ( ) ) { left_ans . push_back ( s [ i ] ) ; right_ans . push_back ( t ) ; set_str . erase ( s [ i ] ) ; set_str . erase ( t ) ; } } for ( auto x : left_ans ) { cout << x ; } cout << mid ; reverse ( right_ans . begin ( ) , right_ans . end ( ) ) ; for ( auto x : right_ans ) { cout << x ; } } int main ( ) { int N = 4 , M = 3 ; string s [ ] = { " omg " , " bbb " , " ffd " , " gmo " } ; max_len ( s , N , M ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimum_length ( int x1 , int y1 , int x2 , int y2 , string str ) { int n = str . size ( ) ; int pos1 , pos2 , pos3 , pos4 ; pos1 = -1 ; pos2 = -1 ; pos3 = -1 ; pos4 = -1 ; if ( x1 == x2 && y1 == y2 ) { cout << 0 << endl ; } else { for ( int i = 0 ; i < n ; i ++ ) { if ( x2 > x1 ) { if ( str [ i ] == ' E ' ) { x1 = x1 + 1 ; if ( x1 == x2 ) { pos1 = i ; } } } if ( x2 < x1 ) { if ( str [ i ] == ' W ' ) { x1 = x1 - 1 ; if ( x1 == x2 ) { pos2 = i ; } } } if ( y2 > y1 ) { if ( str [ i ] == ' N ' ) { y1 = y1 + 1 ; if ( y1 == y2 ) { pos3 = i ; } } } if ( y2 < y1 ) { if ( str [ i ] == ' S ' ) { y1 = y1 - 1 ; if ( y1 == y2 ) { pos4 = i ; } } } } int z ; z = max ( max ( max ( pos1 , pos2 ) , pos3 ) , pos4 ) ; if ( x1 == x2 && y1 == y2 ) { cout << z + 1 << endl ; } else { cout << " - 1" << endl ; } } } int main ( ) { string str = " SESNW " ; int x1 = 0 , x2 = 1 , y1 = 0 , y2 = 1 ; minimum_length ( x1 , y1 , x2 , y2 , str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string ShortenString ( string str1 ) { stack < char > st ; int i = 0 ; while ( i < str1 . length ( ) ) { if ( st . empty ( ) || str1 [ i ] != st . top ( ) ) { st . push ( str1 [ i ] ) ; i ++ ; } else { st . pop ( ) ; i ++ ; } } if ( st . empty ( ) ) { return ( " Empty ▁ String " ) ; } else { string short_string = " " ; while ( ! st . empty ( ) ) { short_string = st . top ( ) + short_string ; st . pop ( ) ; } return ( short_string ) ; } } int main ( ) { string str1 = " azzxzy " ; cout << ShortenString ( str1 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int fact ( int n ) { int res = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { res = res * i ; } return res ; } int distinctWays ( string str1 , string str2 ) { int n = str1 . length ( ) ; int m = str2 . length ( ) ; if ( n == m ) { return 2 * fact ( n ) * fact ( m ) ; } return fact ( n ) * fact ( m ) ; } int main ( ) { string str1 = " aegh " ; string str2 = " rsw " ; cout << distinctWays ( str1 , str2 ) ; }

Accumulator variables: i, stdc
Iterator variables: i