dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define CHILDREN  26
#define MAX  100
struct trie { trie * child [ CHILDREN ] ; bool endOfWord ; } ; trie * createNode ( ) { trie * temp = new trie ( ) ; temp -> endOfWord = false ; for ( int i = 0 ; i < CHILDREN ; i ++ ) { temp -> child [ i ] = NULL ; } return temp ; } void insertRecursively ( trie * itr , string str , int i ) { if ( i < str . length ( ) ) { int index = str [ i ] - ' a ' ; if ( itr -> child [ index ] == NULL ) { itr -> child [ index ] = createNode ( ) ; } insertRecursively ( itr -> child [ index ] , str , i + 1 ) ; } else { itr -> endOfWord = true ; } } void insert ( trie * itr , string str ) { insertRecursively ( itr , str , 0 ) ; } bool isLeafNode ( trie * root ) { return root -> endOfWord != false ; } void displayContent ( trie * root , char str [ ] , int level ) { if ( isLeafNode ( root ) ) { str [ level ] = ' \0' ; cout << str << endl ; } for ( int i = CHILDREN - 1 ; i >= 0 ; i -- ) { if ( root -> child [ i ] ) { str [ level ] = i + ' a ' ; displayContent ( root -> child [ i ] , str , level + 1 ) ; } } } void display ( trie * itr ) { int level = 0 ; char str [ MAX ] ; displayContent ( itr , str , level ) ; } int main ( ) { trie * root = createNode ( ) ; insert ( root , " their " ) ; insert ( root , " there " ) ; insert ( root , " answer " ) ; insert ( root , " any " ) ; display ( root ) ; return 0 ; }

Index/key variables: CHILDREN, MAX, i, index, level
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: endOfWord
Class/struct names: trie
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compare ( string s , string t ) { int ps , pt , i ; ps = -1 ; for ( i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] == ' # ' && ps != -1 ) ps -= 1 ; else if ( s [ i ] != ' # ' ) { s = s [ i ] ; ps += 1 ; } } pt = -1 ; for ( i = 0 ; i < t . size ( ) ; i ++ ) { if ( t [ i ] == ' # ' && pt != -1 ) pt -= 1 ; else if ( t [ i ] != ' # ' ) { t [ pt + 1 ] = t [ i ] ; pt += 1 ; } } if ( pt != ps ) return false ; else if ( ps == -1 && pt == -1 ) return true ; else { for ( i = 0 ; i <= pt ; i ++ ) { if ( s [ i ] != t [ i ] ) return false ; } return true ; } } int main ( ) { string s = " geee # e # ks " ; string t = " gee # # eeks " ; if ( compare ( s , t ) ) cout << " True " ; else cout << " False " ; }

Index/key variables: i
Accumulator variables: i, ps, pt, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > v ( 26 ) ; void calculate ( string s ) { for ( int i = 0 ; i < s . size ( ) ; i ++ ) { v [ s [ i ] - ' a ' ] . push_back ( i ) ; } } void query ( int L , int R ) { int duplicates = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { auto first = lower_bound ( v [ i ] . begin ( ) , v [ i ] . end ( ) , L - 1 ) ; if ( first != v [ i ] . end ( ) && * first < R ) { first ++ ; if ( first != v [ i ] . end ( ) && * first < R ) duplicates ++ ; } } cout << duplicates << endl ; } int main ( ) { string s = " geeksforgeeks " ; int Q = 2 ; int l1 = 1 , r1 = 5 ; int l2 = 4 , r2 = 8 ; calculate ( s ) ; query ( l1 , r1 ) ; query ( l2 , r2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: duplicates, first, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void group_formed ( string S ) { int count = 1 ; for ( int i = 0 ; i < S . size ( ) - 1 ; i ++ ) { if ( S [ i ] != S [ i + 1 ] ) count += 1 ; } cout << ( count ) ; } int main ( ) { string S = " TTWWW " ; group_formed ( S ) ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int value ( char x ) { return ( int ) ( x - ' a ' ) ; } string maximumProduct ( string str , int n ) { string answer = " " , curr = " " ; long long maxProduct = 0 , product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { product *= 1LL * value ( str [ i ] ) ; curr += str [ i ] ; if ( product >= maxProduct ) { maxProduct = product ; answer = curr ; } if ( product == 0 ) { product = 1 ; curr = " " ; } } return answer ; } int main ( ) { string str = " sdtfakdhdahdzz " ; int n = str . size ( ) ; cout << maximumProduct ( str , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: curr, i, product, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( string a , string b ) { int l = a . length ( ) ; int min = 0 , max = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( a [ i ] == ' + ' b [ i ] == ' + ' a [ i ] != b [ i ] ) max ++ ; if ( a [ i ] != ' + ' && b [ i ] != ' + ' && a [ i ] != b [ i ] ) min ++ ; } cout << min + max << endl ; } int main ( ) { string s1 = " a + c " , s2 = " + + b " ; solve ( s1 , s2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, max, min, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int noOfDeletions ( string str , char k ) { int ans = 0 , cnt = 0 , pos = 0 ; while ( pos < str . length ( ) && str [ pos ] != k ) { pos ++ ; } int i = pos ; while ( i < str . length ( ) ) { while ( i < str . length ( ) && str [ i ] == k ) { i = i + 1 ; } ans = ans + cnt ; cnt = 0 ; while ( i < str . length ( ) && str [ i ] != k ) { i = i + 1 ; cnt = cnt + 1 ; } } return ans ; } int main ( ) { string str1 = " ababababa " ; char k1 = ' a ' ; cout << noOfDeletions ( str1 , k1 ) << endl ; string str2 = " kprkkoinkopt " ; char k2 = ' k ' ; cout << noOfDeletions ( str2 , k2 ) << endl ; }

Index/key variables: i, pos
Accumulator variables: pos, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int val ( char c ) { if ( c >= '0' && c <= '9' ) return ( int ) c - '0' ; else return ( int ) c - ' A ' + 10 ; } int toDeci ( string str , int base ) { int len = str . size ( ) ; int power = 1 ; int num = 0 ; int i ; for ( i = len - 1 ; i >= 0 ; i -- ) { if ( val ( str [ i ] ) >= base ) { return -1 ; } num += val ( str [ i ] ) * power ; power = power * base ; } return num ; } void checkCorrespond ( vector < string > str , int x ) { int counter = 0 ; int n = str . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 2 ; j <= 36 ; j ++ ) { if ( toDeci ( str [ i ] , j ) == x ) { counter ++ ; break ; } } } if ( counter == n ) cout << " YES " << " STRNEWLINE " ; else cout << " NO " << " STRNEWLINE " ; } int main ( ) { int x = 16 ; vector < string > str = { "10000" , "20" , "16" } ; checkCorrespond ( str , x ) ; return 0 ; }

Index/key variables: i
Accumulator variables: counter, i, j, num, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LexicoLesserStrings ( string s ) { int count = 0 ; int len ; len = s . size ( ) ; for ( int i = 0 ; i < len ; i ++ ) { count += ( s [ i ] - ' a ' ) * pow ( 26 , len - i - 1 ) ; } return count ; } int countString ( string S1 , string S2 ) { int countS1 , countS2 , totalString ; countS1 = LexicoLesserStrings ( S1 ) ; countS2 = LexicoLesserStrings ( S2 ) ; totalString = countS2 - countS1 - 1 ; return ( totalString < 0 ? 0 : totalString ) ; } int main ( ) { string S1 , S2 ; S1 = " cda " ; S2 = " cef " ; cout << countString ( S1 , S2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char x ) { x = tolower ( x ) ; return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } string longestVowelSubsequence ( string str ) { string answer = " " ; int n = str . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isVowel ( str [ i ] ) ) { answer += str [ i ] ; } } return answer ; } int main ( ) { string str = " geeksforgeeks " ; cout << longestVowelSubsequence ( str ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMaxFrequency ( string s ) { int arr [ 26 ] = { 0 } ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) arr [ s [ i ] - ' a ' ] ++ ; unordered_map < int , int > hash ; for ( int i = 0 ; i < 26 ; i ++ ) if ( arr [ i ] != 0 ) hash [ arr [ i ] ] ++ ; int max_count = 0 , res = -1 ; for ( auto i : hash ) { if ( max_count < i . second ) { res = i . first ; max_count = i . second ; } } cout << " Frequency ▁ " << res << " ▁ is ▁ repeated ▁ " << max_count << " ▁ times " ; } int main ( ) { string s = " geeksgeeks " ; findMaxFrequency ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findString ( string A , string B ) { int dist = 0 ; for ( int i = 0 ; A [ i ] ; i ++ ) { if ( A [ i ] != B [ i ] ) { dist ++ ; } } if ( dist & 1 ) { cout << " Not ▁ Possible " << endl ; } else { string res = " " ; int K = dist / 2 ; for ( int i = 0 ; A [ i ] ; i ++ ) { if ( A [ i ] != B [ i ] && K > 0 ) { res . push_back ( B [ i ] ) ; K -- ; } else if ( A [ i ] != B [ i ] ) { res . push_back ( A [ i ] ) ; } else { res . push_back ( A [ i ] ) ; } } cout << res << endl ; } } int main ( ) { string A = "1001010" ; string B = "0101010" ; findString ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: K, dist, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maximumSuffix ( string s , int n , int k ) { int i = s . length ( ) - 1 ; int arr [ 26 ] = { 0 } ; string suffix = " " ; while ( i > -1 ) { int index = s [ i ] - ' a ' ; if ( arr [ index ] < n ) { arr [ index ] ++ ; suffix += s [ i ] ; i -- ; continue ; } if ( k == 0 ) break ; k -- ; i -- ; } reverse ( suffix . begin ( ) , suffix . end ( ) ) ; cout << suffix ; } int main ( ) { string str = " iahagafedcba " ; int n = 1 , k = 2 ; maximumSuffix ( str , n , k ) ; return 0 ; }

Index/key variables: i, index
Accumulator variables: i, k, stdc, suffix
C++ program:
#include <bits/stdc++.h>
using namespace std ; string xoring ( string a , string b , int n ) { string ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == b [ i ] ) ans += "0" ; else ans += "1" ; } return ans ; } int main ( ) { string a = "1010" ; string b = "1101" ; int n = a . length ( ) ; string c = xoring ( a , b , n ) ; cout << c << endl ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void kthString ( int n , int k ) { int total = 0 ; int i = 1 ; while ( total < k ) { total = total + n - i ; i ++ ; } int first_y_position = i - 1 ; int second_y_position = k - ( total - n + first_y_position ) ; for ( int j = 1 ; j < first_y_position ; j ++ ) cout << " x " ; cout << " y " ; int j = first_y_position + 1 ; while ( second_y_position > 1 ) { cout << " x " ; second_y_position -- ; j ++ ; } cout << " y " ; while ( j < n ) { cout << " x " ; j ++ ; } } int main ( ) { int n = 5 ; int k = 7 ; kthString ( n , k ) ; return 0 ; }

Accumulator variables: i, j, second_y_position, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findLargest ( int N ) { string largest = string ( N , '7' ) ; return largest ; } string findSmallest ( int N ) { string smallest = "1" + string ( ( N - 1 ) , '0' ) ; return smallest ; } void printLargestSmallest ( int N ) { cout << " Largest : ▁ " << findLargest ( N ) << endl ; cout << " Smallest : ▁ " << findSmallest ( N ) << endl ; } int main ( ) { int N = 4 ; printLargestSmallest ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned long long countSubstr ( string & s , int k ) { int n = s . length ( ) ; int l = n - 1 ; int r = n - 1 ; int arr [ n ] ; int last_indexof1 = -1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '1' ) { arr [ i ] = i ; last_indexof1 = i ; } else { arr [ i ] = last_indexof1 ; } } unsigned long long no_of_substr = 0 ; for ( r = n - 1 ; r >= 0 ; r -- ) { l = r ; while ( l >= 0 && ( r - l + 1 ) <= 64 && stoull ( s . substr ( l , r - l + 1 ) , 0 , 2 ) < k ) { l -- ; } if ( r - l + 1 <= 64 ) no_of_substr += l + 1 ; else { no_of_substr += arr [ l + 1 ] + 1 ; } } return no_of_substr ; } int main ( ) { string s = "11100" ; unsigned long long int k = 3 ; cout << countSubstr ( s , k ) ; }

Index/key variables: i, n
Accumulator variables: i, l, no_of_substr, r, stdc
Iterator variables: i, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPerfectCubeString ( string str ) { int sum = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) sum += ( int ) str [ i ] ; long double cr = round ( cbrt ( sum ) ) ; return ( cr * cr * cr == sum ) ; } int main ( ) { string str = " ll " ; if ( isPerfectCubeString ( str ) ) cout << " Yes " ; else cout << " No " ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int XorAscii ( string str , int len ) { int ans = int ( str [ 0 ] ) ; for ( int i = 1 ; i < len ; i ++ ) { ans = ( ans ^ ( int ( str [ i ] ) ) ) ; } return ans ; } int main ( ) { string str = " geeksforgeeks " ; int len = str . length ( ) ; cout << XorAscii ( str , len ) << endl ; str = " GfG " ; len = str . length ( ) ; cout << XorAscii ( str , len ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include " bits / stdc + + . h "
using namespace std ; void CamelCase ( vector < string > & words , string pattern ) { map < string , vector < string > > map ; for ( int i = 0 ; i < words . size ( ) ; i ++ ) { string str = " " ; int l = words [ i ] . length ( ) ; for ( int j = 0 ; j < l ; j ++ ) { if ( words [ i ] [ j ] >= ' A ' && words [ i ] [ j ] <= ' Z ' ) { str += words [ i ] [ j ] ; map [ str ] . push_back ( words [ i ] ) ; } } } bool wordFound = false ; for ( auto & it : map ) { if ( it . first == pattern ) { wordFound = true ; for ( auto & itt : it . second ) { cout << itt << endl ; } } } if ( ! wordFound ) { cout << " No ▁ match ▁ found " ; } } int main ( ) { vector < string > words = { " Hi " , " Hello " , " HelloWorld " , " HiTech " , " HiGeek " , " HiTechWorld " , " HiTechCity " , " HiTechLab " } ; string pattern = " HT " ; CamelCase ( words , pattern ) ; return 0 ; }

Index/key variables: i, j, str
Accumulator variables: i, j, str
Iterator variables: i, j
Boolean variables: wordFound
C++ program:
#include <bits/stdc++.h>
using namespace std ; string encryption ( string s ) { int l = s . length ( ) ; int b = ceil ( sqrt ( l ) ) ; int a = floor ( sqrt ( l ) ) ; string encrypted ; if ( b * a < l ) { if ( min ( b , a ) == b ) { b = b + 1 ; } else { a = a + 1 ; } } char arr [ a ] [ b ] ; memset ( arr , ' ▁ ' , sizeof ( arr ) ) ; int k = 0 ; for ( int j = 0 ; j < a ; j ++ ) { for ( int i = 0 ; i < b ; i ++ ) { if ( k < l ) { arr [ j ] [ i ] = s [ k ] ; } k ++ ; } } for ( int j = 0 ; j < b ; j ++ ) { for ( int i = 0 ; i < a ; i ++ ) { encrypted = encrypted + arr [ i ] [ j ] ; } } return encrypted ; } string decryption ( string s ) { int l = s . length ( ) ; int b = ceil ( sqrt ( l ) ) ; int a = floor ( sqrt ( l ) ) ; string decrypted ; char arr [ a ] [ b ] ; memset ( arr , ' ▁ ' , sizeof ( arr ) ) ; int k = 0 ; for ( int j = 0 ; j < b ; j ++ ) { for ( int i = 0 ; i < a ; i ++ ) { if ( k < l ) { arr [ j ] [ i ] = s [ k ] ; } k ++ ; } } for ( int j = 0 ; j < a ; j ++ ) { for ( int i = 0 ; i < b ; i ++ ) { decrypted = decrypted + arr [ i ] [ j ] ; } } return decrypted ; } int main ( ) { string s = " Geeks ▁ For ▁ Geeks " ; string encrypted ; string decrypted ; encrypted = encryption ( s ) ; cout << encrypted << endl ; decrypted = decryption ( encrypted ) ; cout << decrypted ; return 0 ; }

Index/key variables: a, b, i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int checkIfAllVowels ( string str ) { int hash [ 5 ] = { 0 } ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == ' A ' str [ i ] == ' a ' ) hash [ 0 ] = 1 ; else if ( str [ i ] == ' E ' str [ i ] == ' e ' ) hash [ 1 ] = 1 ; else if ( str [ i ] == ' I ' str [ i ] == ' i ' ) hash [ 2 ] = 1 ; else if ( str [ i ] == ' O ' str [ i ] == ' o ' ) hash [ 3 ] = 1 ; else if ( str [ i ] == ' U ' str [ i ] == ' u ' ) hash [ 4 ] = 1 ; } for ( int i = 0 ; i < 5 ; i ++ ) { if ( hash [ i ] == 0 ) { return 1 ; } } return 0 ; } int checkIfAllVowelsArePresent ( string str ) { if ( checkIfAllVowels ( str ) ) cout << " Not ▁ Accepted STRNEWLINE " ; else cout << " Accepted STRNEWLINE " ; } int main ( ) { string str = " aeioubc " ; checkIfAllVowelsArePresent ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallest ( string s ) { vector < int > a ( s . length ( ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) a [ i ] = s [ i ] - '0' ; vector < int > b ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { if ( ( a [ i ] ) % 2 != 0 ) b . push_back ( a [ i ] ) ; } sort ( b . begin ( ) , b . end ( ) ) ; if ( b . size ( ) > 1 ) return ( b [ 0 ] ) * 10 + ( b [ 1 ] ) ; return -1 ; } int main ( ) { cout << ( smallest ( "15470" ) ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void converthenumber ( int n ) { string s = to_string ( n ) ; string res ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] == '1' s [ i ] == '3' s [ i ] == '5' s [ i ] == '7' s [ i ] == '9' ) res += s [ i ] ; if ( res . size ( ) == 2 ) break ; } if ( res . size ( ) == 2 ) cout << res << endl ; else cout << " - 1" << endl ; } int main ( ) { int n = 18720 ; converthenumber ( n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void longestPalindrome ( string a [ ] , int n ) { string pair1 [ n ] ; string pair2 [ n ] ; int r = 0 ; for ( int i = 0 ; i < n ; i ++ ) { string s = a [ i ] ; reverse ( s . begin ( ) , s . end ( ) ) ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( a [ i ] != " " && a [ j ] != " " ) { if ( s == a [ j ] ) { pair1 [ r ] = a [ i ] ; pair2 [ r ++ ] = a [ j ] ; a [ i ] = " " ; a [ j ] = " " ; break ; } } } } string s1 = " " ; for ( int i = 0 ; i < n ; i ++ ) { string s = a [ i ] ; reverse ( a [ i ] . begin ( ) , a [ i ] . end ( ) ) ; if ( a [ i ] != " " ) { if ( a [ i ] == s ) { s1 = a [ i ] ; break ; } } } string ans = " " ; for ( int i = 0 ; i < r ; i ++ ) { ans = ans + pair1 [ i ] ; } if ( s1 != " " ) { ans = ans + s1 ; } for ( int j = r - 1 ; j >= 0 ; j -- ) { ans = ans + pair2 [ j ] ; } cout << ans << endl ; } int main ( ) { string a1 [ 2 ] = { " aba " , " aba " } ; int n1 = sizeof ( a1 ) / sizeof ( a1 [ 0 ] ) ; longestPalindrome ( a1 , n1 ) ; string a2 [ 5 ] = { " abc " , " dba " , " kop " , " abd " , " cba " } ; int n2 = sizeof ( a2 ) / sizeof ( a2 [ 0 ] ) ; longestPalindrome ( a2 , n2 ) ; }

Index/key variables: i, j, n, r
Accumulator variables: i, j, r, stdc
Iterator variables: i, j
C++ program:
#include " bits / stdc + + . h "
using namespace std ; void printValue ( char digit ) { switch ( digit ) { case '0' : cout << " Zero ▁ " ; break ; case '1' : cout << " One ▁ " ; break ; case '2' : cout << " Two ▁ " ; break ; case '3' : cout << " Three ▁ " ; break ; case '4' : cout << " Four ▁ " ; break ; case '5' : cout << " Five ▁ " ; break ; case '6' : cout << " Six ▁ " ; break ; case '7' : cout << " Seven ▁ " ; break ; case '8' : cout << " Eight ▁ " ; break ; case '9' : cout << " Nine ▁ " ; break ; } } void printWord ( string N ) { int i , length = N . length ( ) ; for ( i = 0 ; i < length ; i ++ ) { printValue ( N [ i ] ) ; } } int main ( ) { string N = "123" ; printWord ( N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class TrieNode { public : char val ; map < char , TrieNode * > children ; int visited ; TrieNode ( char x ) { val = x ; visited = 0 ; } } ; class Trie { public : TrieNode * head ; Trie ( ) { head = new TrieNode ( ' \0' ) ; } void addWord ( string s ) { TrieNode * temp = head ; const unsigned int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char ch = s [ i ] ; if ( ! temp -> children [ ch ] ) { temp -> children [ ch ] = new TrieNode ( ch ) ; } temp = temp -> children [ ch ] ; temp -> visited ++ ; } } int dfs ( TrieNode * node , int & ans , int depth ) { int vis = 0 ; for ( auto child : node -> children ) { vis += dfs ( child . second , ans , depth + 1 ) ; } node -> visited -= vis ; int string_pair = 0 ; if ( node -> visited > 1 ) { string_pair = ( node -> visited / 2 ) ; ans += ( depth * string_pair ) ; node -> visited -= ( 2 * string_pair ) ; } return ( 2 * string_pair + vis ) ; } int dfshelper ( ) { int ans = 0 ; dfs ( head , ans , 0 ) ; return ans ; } } ; int main ( ) { Trie T ; string str [ ] = { " babab " , " ababb " , " abbab " , " aaaaa " , " babaa " , " babbb " } ; int n = 6 ; for ( int i = 0 ; i < n ; i ++ ) { T . addWord ( str [ i ] ) ; } int ans = T . dfshelper ( ) ; cout << ans << endl ; return 0 ; }

Index/key variables: ch, i
Accumulator variables: ans, i, stdc, vis, visited
Iterator variables: child, i
Class/struct names: Trie, TrieNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int ALPHABET_SIZE = 26 ; struct TrieNode { struct TrieNode * children [ ALPHABET_SIZE ] ; bool isEndOfWord ; } ; struct TrieNode * getNode ( void ) { struct TrieNode * pNode = new TrieNode ; pNode -> isEndOfWord = false ; for ( int i = 0 ; i < ALPHABET_SIZE ; i ++ ) pNode -> children [ i ] = NULL ; return pNode ; } void insert ( struct TrieNode * root , string key ) { struct TrieNode * pCrawl = root ; for ( int i = 0 ; i < key . length ( ) ; i ++ ) { int index = key [ i ] - ' a ' ; if ( ! pCrawl -> children [ index ] ) pCrawl -> children [ index ] = getNode ( ) ; pCrawl = pCrawl -> children [ index ] ; } pCrawl -> isEndOfWord = true ; } bool search ( struct TrieNode * root , string key ) { struct TrieNode * pCrawl = root ; for ( int i = 0 ; i < key . length ( ) ; i ++ ) { int index = key [ i ] - ' a ' ; if ( ! pCrawl -> children [ index ] ) return false ; pCrawl = pCrawl -> children [ index ] ; } return ( pCrawl != NULL && pCrawl -> isEndOfWord ) ; } void wordBreakAll ( TrieNode * root , string word , int n , string result ) { for ( int i = 1 ; i <= n ; i ++ ) { string prefix = word . substr ( 0 , i ) ; if ( search ( root , prefix ) ) { if ( i == n ) { result += prefix ; cout << " TABSYMBOL " << result << endl ; return ; } wordBreakAll ( root , word . substr ( i , n - i ) , n - i , result + prefix + " ▁ " ) ; } } } int main ( ) { struct TrieNode * root = getNode ( ) ; string dictionary [ ] = { " sam " , " sung " , " samsung " } ; int n = sizeof ( dictionary ) / sizeof ( string ) ; for ( int i = 0 ; i < n ; i ++ ) { insert ( root , dictionary [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { cout << dictionary [ i ] << " : ▁ STRNEWLINE " ; wordBreakAll ( root , dictionary [ i ] , dictionary [ i ] . length ( ) , " " ) ; } return 0 ; }

Index/key variables: ALPHABET_SIZE, i, index
Accumulator variables: i, result, stdc
Iterator variables: i
Boolean variables: isEndOfWord
Class/struct names: TrieNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; double jaro_distance ( string s1 , string s2 ) { if ( s1 == s2 ) return 1.0 ; int len1 = s1 . length ( ) , len2 = s2 . length ( ) ; int max_dist = floor ( max ( len1 , len2 ) / 2 ) - 1 ; int match = 0 ; int hash_s1 [ s1 . length ( ) ] = { 0 } , hash_s2 [ s2 . length ( ) ] = { 0 } ; for ( int i = 0 ; i < len1 ; i ++ ) { for ( int j = max ( 0 , i - max_dist ) ; j < min ( len2 , i + max_dist + 1 ) ; j ++ ) if ( s1 [ i ] == s2 [ j ] && hash_s2 [ j ] == 0 ) { hash_s1 [ i ] = 1 ; hash_s2 [ j ] = 1 ; match ++ ; break ; } } if ( match == 0 ) return 0.0 ; double t = 0 ; int point = 0 ; for ( int i = 0 ; i < len1 ; i ++ ) if ( hash_s1 [ i ] ) { while ( hash_s2 [ point ] == 0 ) point ++ ; if ( s1 [ i ] != s2 [ point ++ ] ) t ++ ; } t /= 2 ; return ( ( ( double ) match ) / ( ( double ) len1 ) + ( ( double ) match ) / ( ( double ) len2 ) + ( ( double ) match - t ) / ( ( double ) match ) ) / 3.0 ; } int main ( ) { string s1 = " CRATE " , s2 = " TRACE " ; cout << jaro_distance ( s1 , s2 ) << endl ; return 0 ; }

Index/key variables: i, j, point
Accumulator variables: i, j, match, point, stdc, t
Iterator variables: i, j