codeparrot/xlcost-text-to-code huggingface dataset:
Count substrings with each character occurring at most k times | CPP program to count number of substrings in which each character has count less than or equal to k . ; variable to store count of substrings . ; array to store count of each character . ; Initialize all characters count to zero . ; increment character count ; check only the count of current character because only the count of this character is changed . The ending point is incremented to current position only if all other characters have count at most k and hence their count is not checked . If count is less than k , then increase ans by 1. ; if count is less than k , then break as subsequent substrings for this starting point will also have count greater than k and hence are reduntant to check . ; return the final count of substrings . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findSubstrings ( string s , int k ) { int ans = 0 ; int cnt [ 26 ] ; int i , j , n = s . length ( ) ; for ( i = 0 ; i < n ; i ++ ) { memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( j = i ; j < n ; j ++ ) { cnt [ s [ j ] - ' a ' ] ++ ; if ( cnt [ s [ j ] - ' a ' ] <= k ) ans ++ ; else break ; } } return ans ; } int main ( ) { string S = " aaabb " ; int k = 2 ; cout << findSubstrings ( S , k ) ; return 0 ; }
Check if characters of one string can be swapped to form other | C ++ program to check if characters of one string can be swapped to form other ; if length is not same print no ; Count frequencies of character in first string . ; iterate through the second string decrement counts of characters in second string ; Since lengths are same , some value would definitely become negative if result is false . ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX = 26 ; bool targetstring ( string str1 , string str2 ) { int l1 = str1 . length ( ) ; int l2 = str2 . length ( ) ; if ( l1 != l2 ) return false ; int map [ MAX ] = { 0 } ; for ( int i = 0 ; i < l1 ; i ++ ) map [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) { map [ str2 [ i ] - ' a ' ] -- ; if ( map [ str2 [ i ] - ' a ' ] < 0 ) return false ; } return true ; } int main ( ) { string str1 = " geeksforgeeks " ; string str2 = " geegeeksksfor " ; if ( targetstring ( str1 , str2 ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }
Find the Number which contain the digit d | C ++ program to print the number which contain the digit d from 0 to n ; Returns true if d is present as digit in number x . ; Breal loop if d is present as digit ; If loop broke ; function to display the values ; Check all numbers one by one ; checking for digit ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDigitPresent ( int x , int d ) { while ( x > 0 ) { if ( x % 10 == d ) break ; x = x / 10 ; } return ( x > 0 ) ; } void printNumbers ( int n , int d ) { for ( int i = 0 ; i <= n ; i ++ ) if ( i == d || isDigitPresent ( i , d ) ) cout << i << " ▁ " ; } int main ( ) { int n = 47 , d = 7 ; printNumbers ( n , d ) ; return 0 ; }
Find one extra character in a string | CPP program to find extra character in one string ; store string values in map ; store second string in map with frequency ; store first string in map with frequency ; if the frequency is 1 then this character is which is added extra ; Driver code ; given string ; find Extra Character
#include <bits/stdc++.h> NEW_LINE using namespace std ; char findExtraCharcter ( string strA , string strB ) { unordered_map < char , int > m1 ; for ( int i = 0 ; i < strB . length ( ) ; i ++ ) m1 [ strB [ i ] ] ++ ; for ( int i = 0 ; i < strA . length ( ) ; i ++ ) m1 [ strA [ i ] ] -- ; for ( auto h1 = m1 . begin ( ) ; h1 != m1 . end ( ) ; h1 ++ ) { if ( h1 -> second == 1 ) return h1 -> first ; } } int main ( ) { string strA = " abcd " ; string strB = " cbdad " ; cout << findExtraCharcter ( strA , strB ) ; }
Find one extra character in a string | CPP program to find extra character in one string ; result store the result ; traverse string A till end and xor with res ; xor with res ; traverse string B till end and xor with res ; xor with res ; print result at the end ; given string
#include <iostream> NEW_LINE using namespace std ; char findExtraCharcter ( string strA , string strB ) { int res = 0 , i ; for ( i = 0 ; i < strA . length ( ) ; i ++ ) { res ^= strA [ i ] ; } for ( i = 0 ; i < strB . length ( ) ; i ++ ) { res ^= strB [ i ] ; } return ( ( char ) ( res ) ) ; } int main ( ) { string strA = " abcd " ; string strB = " cbdad " ; cout << findExtraCharcter ( strA , strB ) ; return 0 ; }
Find one extra character in a string | C ++ program to find extra character in one string ; Determine string with extra character . ; Add character codes of both the strings ; Add last character code of large string . ; Minus the character code of smaller string from the character code of large string . The result will be the extra character code . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; char findExtraCharacter ( string s1 , string s2 ) { string smallStr ; string largeStr ; if ( s1 . size ( ) > s2 . size ( ) ) { smallStr = s2 ; largeStr = s1 ; } else { smallStr = s1 ; largeStr = s2 ; } int smallStrCodeTotal = 0 ; int largeStrCodeTotal = 0 ; int i = 0 ; for ( ; i < smallStr . size ( ) ; i ++ ) { smallStrCodeTotal += smallStr [ i ] ; largeStrCodeTotal += largeStr [ i ] ; } largeStrCodeTotal += largeStr [ i ] ; int intChar = largeStrCodeTotal - smallStrCodeTotal ; return ( char ) intChar ; } int main ( ) { string s1 = " abcd " ; string s2 = " cbdae " ; char extraChar = findExtraCharacter ( s1 , s2 ) ; cout << " Extra ▁ character : ▁ " << ( extraChar ) << endl ; return 0 ; }
Function to copy string ( Iterative and Recursive ) | Iterative CPP Program to copy one String to another . ; Function to copy one string to other assuming that other string has enough space . ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void myCopy ( char s1 [ ] , char s2 [ ] ) { int i = 0 ; for ( i = 0 ; s1 [ i ] != ' \0' ; i ++ ) s2 [ i ] = s1 [ i ] ; s2 [ i ] = ' \0' ; } int main ( ) { char s1 [ 100 ] = " GEEKSFORGEEKS " ; char s2 [ 100 ] = " " ; myCopy ( s1 , s2 ) ; cout << s2 ; return 0 ; }
Evaluate an array expression with numbers , + and | C ++ program to find sum of given array of string type in integer form ; Function to find the sum of given array ; if string is empty ; stoi function to convert string into integer ; stoi function to convert string into integer ; Find operator ; If operator is equal to ' + ' , add value in sum variable else subtract ; Driver Function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculateSum ( string arr [ ] , int n ) { if ( n == 0 ) return 0 ; string s = arr [ 0 ] ; int value = stoi ( s ) ; int sum = value ; for ( int i = 2 ; i < n ; i = i + 2 ) { s = arr [ i ] ; int value = stoi ( s ) ; char operation = arr [ i - 1 ] [ 0 ] ; if ( operation == ' + ' ) sum += value ; else sum -= value ; } return sum ; } int main ( ) { string arr [ ] = { "3" , " + " , "4" , " - " , "7" , " + " , "13" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << calculateSum ( arr , n ) ; return 0 ; }
Check if two strings have a common substring | CPP program to heck if two strings have common substring ; function to return true if strings have common substring and no if strings have no common substring ; vector for storing character occurrences ; increment vector index for every character of str1 ; checking common substring of str2 in str1 ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX_CHAR = 26 ; bool twoStrings ( string s1 , string s2 ) { vector < bool > v ( MAX_CHAR , 0 ) ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) v [ s1 [ i ] - ' a ' ] = true ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) if ( v [ s2 [ i ] - ' a ' ] ) return true ; return false ; } int main ( ) { string str1 = " hello " ; string str2 = " world " ; if ( twoStrings ( str1 , str2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
String with maximum number of unique characters | C ++ code to find the largest string ; Function to find string with maximum number of unique characters . ; Index of string with maximum unique characters ; iterate through all strings ; array indicating any alphabet included or not included ; count number of unique alphabets in each string ; keep track of maximum number of alphabets ; print result ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void LargestString ( string * na ) { int N = sizeof ( na ) / sizeof ( na [ 0 ] ) ; int c [ N ] ; int m = 1 ; for ( int j = 0 ; j < N ; j ++ ) { bool character [ 26 ] ; for ( int k = 0 ; k < na [ j ] . size ( ) ; k ++ ) { int x = ( int ) ( na [ j ] [ k ] - ' A ' ) ; if ( na [ j ] [ k ] != ' ▁ ' && character [ x ] == false ) { c [ j ] ++ ; character [ x ] = true ; } } if ( c [ j ] > c [ m ] ) m = j ; } cout << na [ m ] << endl ; } int main ( ) { string na [ ] = { " BOB " , " A ▁ AB ▁ C ▁ JOHNSON " , " ANJALI " , " ASKRIT " , " ARMAN ▁ MALLIK " } ; LargestString ( na ) ; }
Program for length of the longest word in a sentence | C ++ program to find the number of charters in the longest word in the sentence . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int LongestWordLength ( string str ) { int counter = 0 ; string words [ 100 ] ; for ( short i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == ' ▁ ' ) counter ++ ; else words [ counter ] += str [ i ] ; } int length = 0 ; for ( string word : words ) { if ( length < word . length ( ) ) { length = word . length ( ) ; } } return length ; } int main ( ) { string str = " I ▁ am ▁ an ▁ intern ▁ at ▁ geeksforgeeks " ; cout << ( LongestWordLength ( str ) ) ; }
Morse Code Implementation | CPP program to demonstrate Morse code ; function to encode a alphabet as Morse code ; refer to the Morse table image attached in the article ; for space ; character by character print Morse code ; Driver 's code
#include <iostream> NEW_LINE using namespace std ; string morseEncode ( char x ) { switch ( x ) { case ' a ' : return " . - " ; case ' b ' : return " - . . . " ; case ' c ' : return " - . - . " ; case ' d ' : return " - . . " ; case ' e ' : return " . " ; case ' f ' : return " . . - . " ; case ' g ' : return " - - . " ; case ' h ' : return " . . . . " ; case ' i ' : return " . . " ; case ' j ' : return " . - - - " ; case ' k ' : return " - . - " ; case ' l ' : return " . - . . " ; case ' m ' : return " - - " ; case ' n ' : return " - . " ; case ' o ' : return " - - - " ; case ' p ' : return " . - - . " ; case ' q ' : return " - - . - " ; case ' r ' : return " . - . " ; case ' s ' : return " . . . " ; case ' t ' : return " - " ; case ' u ' : return " . . - " ; case ' v ' : return " . . . - " ; case ' w ' : return " . - - " ; case ' x ' : return " - . . - " ; case ' y ' : return " - . - - " ; case ' z ' : return " - - . . " ; case '1' : return " . - - - - " ; case '2' : return " . . - - - " ; case '3' : return " . . . - - " ; case '4' : return " . . . . - " ; case '5' : return " . . . . . " ; case '6' : return " - . . . . " ; case '7' : return " - - . . . " ; case '8' : return " - - - . . " ; case '9' : return " - - - - . " ; case '0' : return " - - - - - " ; default : cerr << " Found ▁ invalid ▁ character : ▁ " << x << ' ▁ ' << std :: endl ; exit ( 0 ) ; } } void morseCode ( string s ) { for ( int i = 0 ; s [ i ] ; i ++ ) cout << morseEncode ( s [ i ] ) ; cout << endl ; } int main ( ) { string s = " geeksforgeeks " ; morseCode ( s ) ; return 0 ; }
Polybius Square Cipher | CPP Program to implement polybius cipher ; function to display polybius cipher text ; convert each character to its encrypted code ; finding row of the table ; finding column of the table ; if character is ' k ' ; if character is greater than ' j ' ; Driver 's Code ; print the cipher of "geeksforgeeks
#include <cmath> NEW_LINE #include <iostream> NEW_LINE using namespace std ; void polybiusCipher ( string s ) { int row , col ; for ( int i = 0 ; s [ i ] ; i ++ ) { row = ceil ( ( s [ i ] - ' a ' ) / 5 ) + 1 ; col = ( ( s [ i ] - ' a ' ) % 5 ) + 1 ; if ( s [ i ] == ' k ' ) { row = row - 1 ; col = 5 - col + 1 ; } else if ( s [ i ] >= ' j ' ) { if ( col == 1 ) { col = 6 ; row = row - 1 ; } col = col - 1 ; } cout << row << col ; } cout << endl ; } int main ( ) { string s = " geeksforgeeks " ; polybiusCipher ( s ) ; return 0 ; }
Minimum removal to make palindrome permutation | CPP Program to find minimum number of removal to make any permutation of the string a palindrome ; function to find minimum removal of characters ; hash to store frequency of each character ; to set hash array to zeros ; count frequency of each character ; count the odd frequency characters ; if count is - 1 return 0 otherwise return count ; Driver 's Code
#include <iostream> NEW_LINE using namespace std ; #define MAX_CHAR  26 NEW_LINE int minRemoval ( string str ) { int hash [ MAX_CHAR ] ; memset ( hash , 0 , sizeof ( hash ) ) ; for ( int i = 0 ; str [ i ] ; i ++ ) hash [ str [ i ] - ' a ' ] ++ ; int count = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( hash [ i ] % 2 ) count ++ ; return ( count == 0 ) ? 0 : count - 1 ; } int main ( ) { string str = " geeksforgeeks " ; cout << minRemoval ( str ) << endl ; return 0 ; }
Union | CPP program to implement Union - Find with union by rank and path compression . ; Arr to represent parent of index i ; Size to represent the number of nodes in subgxrph rooted at index i ; set parent of every node to itself and size of node to one ; Each time we follow a path , find function compresses it further until the path length is greater than or equal to 1. ; while we reach a node whose parent is equal to itself ; Skip one level ; Move to the new level ; A function that does union of two nodes x and y where xr is root node of x and yr is root node of y ; Make yr parent of xr ; Make xr parent of yr ; The main function to check whether a given gxrph contains cycle or not ; Itexrte through all edges of gxrph , find nodes connecting them . If root nodes of both are same , then there is cycle in gxrph . ; find root of i ; find root of adj [ i ] [ j ] ; If same parent ; Make them connect ; Driver progxrm to test above functions ; Initialize the values for arxry Arr and Size ; Adjacency list for gxrph ; call is_cycle to check if it contains cycle
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX_VERTEX = 101 ; int Arr [ MAX_VERTEX ] ; int size [ MAX_VERTEX ] ; void initialize ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) { Arr [ i ] = i ; size [ i ] = 1 ; } } int find ( int i ) { while ( Arr [ i ] != i ) { Arr [ i ] = Arr [ Arr [ i ] ] ; i = Arr [ i ] ; } return i ; } void _union ( int xr , int yr ) { if ( size [ xr ] < size [ yr ] ) { Arr [ xr ] = Arr [ yr ] ; size [ yr ] += size [ xr ] ; } else { Arr [ yr ] = Arr [ xr ] ; size [ xr ] += size [ yr ] ; } } int isCycle ( vector < int > adj [ ] , int V ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < adj [ i ] . size ( ) ; j ++ ) { int x = find ( i ) ; int y = find ( adj [ i ] [ j ] ) ; if ( x == y ) return 1 ; _union ( x , y ) ; } } return 0 ; } int main ( ) { int V = 3 ; initialize ( V ) ; vector < int > adj [ V ] ; adj [ 0 ] . push_back ( 1 ) ; adj [ 0 ] . push_back ( 2 ) ; adj [ 1 ] . push_back ( 2 ) ; if ( isCycle ( adj , V ) ) cout << " Gxrph ▁ contains ▁ Cycle . STRNEWLINE " ; else cout << " Gxrph ▁ does ▁ not ▁ contain ▁ Cycle . STRNEWLINE " ; return 0 ; }
Queries for frequencies of characters in substrings | CPP program to find occurrence of character in substring l to r ; To store count of all character ; To pre - process string from 0 to size of string ; Store occurrence of character i ; Store occurrence o all character upto i ; To return occurrence of character in range l to r ; Return occurrence of character from 0 to r minus its occurrence from 0 to l ; Driver program to test above functions
#include <bits/stdc++.h> NEW_LINE #define MAX_LEN  1005 NEW_LINE #define MAX_CHAR  26 NEW_LINE using namespace std ; int cnt [ MAX_LEN ] [ MAX_CHAR ] ; void preProcess ( string s ) { int n = s . length ( ) ; memset ( cnt , 0 , sizeof ( cnt ) ) ; for ( int i = 0 ; i < n ; i ++ ) cnt [ i ] [ s [ i ] - ' a ' ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) cnt [ i ] [ j ] += cnt [ i - 1 ] [ j ] ; } } int findCharFreq ( int l , int r , char c ) { int count = cnt [ r ] [ c - ' a ' ] ; if ( l != 0 ) count -= cnt [ l - 1 ] [ c - ' a ' ] ; return count ; } int main ( ) { string s = " geeksforgeeks " ; int Q = 4 ; preProcess ( s ) ; cout << findCharFreq ( 0 , 5 , ' e ' ) << endl ; cout << findCharFreq ( 2 , 6 , ' f ' ) << endl ; cout << findCharFreq ( 4 , 7 , ' m ' ) << endl ; cout << findCharFreq ( 0 , 12 , ' e ' ) << endl ; return 0 ; }
Longest Uncommon Subsequence | CPP Program to find longest uncommon subsequence . ; function to calculate length of longest uncommon subsequence ; Case 1 : If strings are equal ; for case 2 and case 3 ; Driver code ; input strings
#include <iostream> NEW_LINE using namespace std ; int findLUSlength ( string a , string b ) { if ( ! a . compare ( b ) ) return 0 ; return max ( a . length ( ) , b . length ( ) ) ; } int main ( ) { string a = " abcdabcd " , b = " abcabc " ; cout << findLUSlength ( a , b ) ; return 0 ; }
Interchanging first and second halves of strings | CPP code to create two new strings by swapping first and second halves ; Function to concatenate two different halves of given strings ; Creating new strings by exchanging the first half of a and b . Please refer below for details of substr . https : www . geeksforgeeks . org / stdsubstr - in - ccpp / ; Driver function ; Calling function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void swapTwoHalves ( string a , string b ) { int la = a . length ( ) ; int lb = b . length ( ) ; string c = a . substr ( 0 , la / 2 ) + b . substr ( lb / 2 , lb ) ; string d = b . substr ( 0 , lb / 2 ) + a . substr ( la / 2 , la ) ; cout << c << endl << d << endl ; } int main ( ) { string a = " remuneration " ; string b = " day " ; swapTwoHalves ( a , b ) ; return 0 ; }
Merge two strings in chunks of given size | C ++ program to merge n number of strings ; Function performing the calculations ; Length of string a ; Length f string b ; Pointers for string a and string b ; pa and pb denote the number of characters of both a and b extracted ; If entire substring of length k can be extracted ; Please refer below link for details of library function https : www . geeksforgeeks . org / stdsubstr - in - ccpp / ; If the remaining string is of length less than k ; If the string has been traversed ; If entire substring of length k can be extracted ; If the remaining string is of length less than k ; If the string has been traversed ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void solve ( string a , string b , int k ) { string s = " " ; int la = a . length ( ) ; int lb = b . length ( ) ; int l = la + lb ; int indexa = 0 , indexb = 0 ; while ( l > 0 ) { int pa = 0 , pb = 0 ; if ( la - indexa >= k ) { s = s + a . substr ( indexa , k ) ; indexa = indexa + k ; pa = k ; } else if ( la - indexa < k && la - indexa > 0 ) { s = s + a . substr ( indexa , la - indexa ) ; pa = la - indexa ; indexa = la ; } else if ( indexa >= la ) pa = 0 ; if ( lb - indexb >= k ) { s = s + b . substr ( indexb , k ) ; pb = k ; indexb = indexb + k ; } else if ( lb - indexb < k && lb - indexb > 0 ) { s = s + b . substr ( indexb , lb - indexb ) ; pb = lb - indexb ; indexb = lb ; } else if ( indexb >= lb ) pb = 0 ; l = l - pa - pb ; } cout << s ; } int main ( ) { string a = " determination " , b = " stance " ; int k = 3 ; solve ( a , b , k ) ; return 0 ; }
Longest sub | C ++ implementation to find the length of the longest substring having frequency of each character less than equal to k ; function to find the length of the longest substring having frequency of each character less than equal to k ; hash table to store frequency of each table ; ' start ' index of the current substring ; to store the maximum length ; traverse the string ' str ' ; get the current character as ' ch ' ; increase frequency of ' ch ' in ' freq [ ] ' ; if frequency of ' ch ' becomes more than ' k ' ; update ' maxLen ' ; decrease frequency of each character as they are encountered from the ' start ' index until frequency of ' ch ' is greater than ' k ' ; decrement frequency by '1' ; increment ' start ' ; update maxLen ; required length ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define SIZE  26 NEW_LINE int longSubstring ( string str , int k ) { int freq [ SIZE ] ; memset ( freq , 0 , sizeof ( freq ) ) ; int start = 0 ; int maxLen = 0 ; char ch ; int n = str . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { ch = str [ i ] ; freq [ ch - ' a ' ] ++ ; if ( freq [ ch - ' a ' ] > k ) { if ( maxLen < ( i - start ) ) maxLen = i - start ; while ( freq [ ch - ' a ' ] > k ) { freq [ str [ start ] - ' a ' ] -- ; start ++ ; } } } if ( maxLen < ( n - start ) ) maxLen = n - start ; return maxLen ; } int main ( ) { string str = " babcaag " ; int k = 1 ; cout << " Length ▁ = ▁ " << longSubstring ( str , k ) ; return 0 ; }
Magical Indices in an array | C ++ program to find number of magical indices in the given array . ; Function to count number of magical indices . ; Array to store parent node of traversal . ; Array to determine whether current node is already counted in the cycle . ; Initialize the arrays . ; Check if current node is already traversed or not . If node is not traversed yet then parent value will be - 1. ; Traverse the graph until an already visited node is not found . ; Check parent value to ensure a cycle is present . ; Count number of nodes in the cycle . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define mp  make_pair NEW_LINE #define pb  push_back NEW_LINE #define mod  1000000007 NEW_LINE int solve ( int A [ ] , int n ) { int i , cnt = 0 , j ; int parent [ n + 1 ] ; int vis [ n + 1 ] ; memset ( parent , -1 , sizeof ( parent ) ) ; memset ( vis , 0 , sizeof ( vis ) ) ; for ( i = 0 ; i < n ; i ++ ) { j = i ; if ( parent [ j ] == -1 ) { while ( parent [ j ] == -1 ) { parent [ j ] = i ; j = ( j + A [ j ] + 1 ) % n ; } if ( parent [ j ] == i ) { while ( ! vis [ j ] ) { vis [ j ] = 1 ; cnt ++ ; j = ( j + A [ j ] + 1 ) % n ; } } } } return cnt ; } int main ( ) { int A [ ] = { 0 , 0 , 0 , 2 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << solve ( A , n ) ; return 0 ; }