codeparrot/xlcost-text-to-code huggingface dataset:
Common characters in n strings | C # Program to find all the common characters in n strings ; primary array for common characters we assume all characters are seen before . ; for each string ; secondary array for common characters Initially marked false ; for every character of ith string ; if character is present in all strings before , mark it . ; Copy whole secondary array into primary ; Displaying common characters ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; public static void commonCharacters ( String [ ] str , int n ) { Boolean [ ] prim = new Boolean [ MAX_CHAR ] ; for ( int i = 0 ; i < prim . Length ; i ++ ) prim [ i ] = true ; for ( int i = 0 ; i < n ; i ++ ) { Boolean [ ] sec = new Boolean [ MAX_CHAR ] ; for ( int s = 0 ; s < sec . Length ; s ++ ) sec [ s ] = false ; for ( int j = 0 ; j < str [ i ] . Length ; j ++ ) { if ( prim [ str [ i ] [ j ] - ' a ' ] ) sec [ str [ i ] [ j ] - ' a ' ] = true ; } Array . Copy ( sec , 0 , prim , 0 , MAX_CHAR ) ; } for ( int i = 0 ; i < 26 ; i ++ ) if ( prim [ i ] ) { Console . Write ( ( char ) ( i + 97 ) ) ; Console . Write ( " ▁ " ) ; } } public static void Main ( String [ ] args ) { String [ ] str = { " geeksforgeeks " , " gemkstones " , " acknowledges " , " aguelikes " } ; int n = str . Length ; commonCharacters ( str , n ) ; } }
Number of positions where a letter can be inserted such that a string becomes palindrome | C # code to find the no . of positions where a letter can be inserted to make it a palindrome . ; Function to check if the string is palindrome ; to know the length of string ; if the given string is a palindrome ( Case - I ) ; Sub - case - III ) ; if the length is even ; sub - case - I ; sub - case - II ; insertion point ; Case - I ; Case - II ; Driver code
using System ; class GFG { static bool isPalindrome ( String s , int i , int j ) { int p = j ; for ( int k = i ; k <= p ; k ++ ) { if ( s [ k ] != s [ p ] ) return false ; p -- ; } return true ; } static int countWays ( String s ) { int n = s . Length ; int count = 0 ; if ( isPalindrome ( s , 0 , n - 1 ) ) { for ( int i = n / 2 ; i < n ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) count ++ ; else break ; } if ( n % 2 == 0 ) { count ++ ; count = 2 * count + 1 ; } else count = 2 * count + 2 ; } else { for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( s [ i ] != s [ n - 1 - i ] ) { int j = n - 1 - i ; if ( isPalindrome ( s , i , n - 2 - i ) ) { for ( int k = i - 1 ; k >= 0 ; k -- ) { if ( s [ k ] != s [ j ] ) break ; count ++ ; } count ++ ; } if ( isPalindrome ( s , i + 1 , n - 1 - i ) ) { for ( int k = n - i ; k < n ; k ++ ) { if ( s [ k ] != s [ i ] ) break ; count ++ ; } count ++ ; } break ; } } } return count ; } public static void Main ( ) { String s = " abca " ; Console . Write ( countWays ( s ) ) ; } }
Count of substrings of a binary string containing K ones | C # program to find count of substring containing exactly K ones ; method returns total number of substring having K ones ; initialize index having zero sum as 1 ; loop over binary characters of string ; update countOfOne variable with value of ith character ; if value reaches more than K , then update result ; add frequency of indices , having sum ( current sum - K ) , to the result ; update frequency of one 's count ; Driver code to test above methods
using System ; public class GFG { static int countOfSubstringWithKOnes ( string s , int K ) { int N = s . Length ; int res = 0 ; int countOfOne = 0 ; int [ ] freq = new int [ N + 1 ] ; freq [ 0 ] = 1 ; for ( int i = 0 ; i < N ; i ++ ) { countOfOne += ( s [ i ] - '0' ) ; if ( countOfOne >= K ) { res += freq [ countOfOne - K ] ; } freq [ countOfOne ] ++ ; } return res ; } static public void Main ( ) { string s = "10010" ; int K = 1 ; Console . WriteLine ( countOfSubstringWithKOnes ( s , K ) ) ; } }
Generate two output strings depending upon occurrence of character in input string . | C # program to print two strings made of character occurring once and multiple times ; function to print two strings generated from single string one with characters occurring onces other with character occurring multiple of times ; initialize hashtable with zero entry ; perform hashing for input string ; generate string ( str1 ) consisting char occurring once and string ( str2 ) consisting char occurring multiple times ; print both strings ; Driver Code
using System ; class GFG { static int MAX_CHAR = 256 ; static void printDuo ( string str ) { int [ ] countChar = new int [ MAX_CHAR ] ; int n = str . Length ; for ( int i = 0 ; i < n ; i ++ ) { countChar [ str [ i ] - ' a ' ] ++ ; } string str1 = " " , str2 = " " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( countChar [ i ] > 1 ) { str2 = str2 + ( char ) ( i + ' a ' ) ; } else if ( countChar [ i ] == 1 ) { str1 = str1 + ( char ) ( i + ' a ' ) ; } } Console . Write ( " String ▁ with ▁ characters ▁ " + " occurring ▁ once : STRNEWLINE " ) ; Console . Write ( str1 + " STRNEWLINE " ) ; Console . Write ( " String ▁ with ▁ characters ▁ occurring ▁ " + " multiple ▁ times : STRNEWLINE " ) ; Console . Write ( str2 + " STRNEWLINE " ) ; Console . Write ( " " ) ; } public static void Main ( ) { string str = " lovetocode " ; printDuo ( str ) ; } }
Next higher palindromic number using the same set of digits | C # implementation to find next higher palindromic number using the same set of digits ; function to reverse the digits in the range i to j in ' num ' ; function to find next higher palindromic number using the same set of digits ; if length of number is less than '3' then no higher palindromic number can be formed ; find the index of last digit in the 1 st half of ' num ' ; Start from the ( mid - 1 ) th digit and find the first digit that is smaller than the digit next to it . ; If no such digit is found , then all digits are in descending order which means there cannot be a greater palindromic number with same set of digits ; Find the smallest digit on right side of ith digit which is greater than num [ i ] up to index ' mid ' ; swap num [ i ] with num [ smallest ] ; as the number is a palindrome , the same swap of digits should be performed in the 2 nd half of ' num ' ; reverse digits in the range ( i + 1 ) to mid ; if n is even , then reverse digits in the range mid + 1 to n - i - 2 ; else if n is odd , then reverse digits in the range mid + 2 to n - i - 2 ; required next higher palindromic number ; Driver Code
using System ; class GFG { public static void reverse ( char [ ] num , int i , int j ) { while ( i < j ) { char temp = num [ i ] ; num [ i ] = num [ j ] ; num [ j ] = temp ; i ++ ; j -- ; } } public static void nextPalin ( char [ ] num , int n ) { if ( n <= 3 ) { Console . WriteLine ( " Not ▁ Possible " ) ; return ; } char temp ; int mid = n / 2 - 1 ; int i , j ; for ( i = mid - 1 ; i >= 0 ; i -- ) if ( num [ i ] < num [ i + 1 ] ) break ; if ( i < 0 ) { Console . WriteLine ( " Not ▁ Possible " ) ; return ; } int smallest = i + 1 ; for ( j = i + 2 ; j <= mid ; j ++ ) if ( num [ j ] > num [ i ] && num [ j ] < num [ smallest ] ) smallest = j ; temp = num [ i ] ; num [ i ] = num [ smallest ] ; num [ smallest ] = temp ; temp = num [ n - i - 1 ] ; num [ n - i - 1 ] = num [ n - smallest - 1 ] ; num [ n - smallest - 1 ] = temp ; reverse ( num , i + 1 , mid ) ; if ( n % 2 == 0 ) reverse ( num , mid + 1 , n - i - 2 ) ; else reverse ( num , mid + 2 , n - i - 2 ) ; String result = new String ( num ) ; Console . WriteLine ( " Next ▁ Palindrome : ▁ " + result ) ; } public static void Main ( ) { String str = "4697557964" ; char [ ] num = str . ToCharArray ( ) ; int n = str . Length ; nextPalin ( num , n ) ; } }
Print N | C # program to print all N - bit binary ; function to generate n digit numbers ; if number generated ; Append 1 at the current number and reduce the remaining places by one ; If more ones than zeros , append 0 to the current number and reduce the remaining places by one ; Driver code ; Function call
using System ; class GFG { static void printRec ( String number , int extraOnes , int remainingPlaces ) { if ( 0 == remainingPlaces ) { Console . Write ( number + " ▁ " ) ; return ; } printRec ( number + "1" , extraOnes + 1 , remainingPlaces - 1 ) ; if ( 0 < extraOnes ) printRec ( number + "0" , extraOnes - 1 , remainingPlaces - 1 ) ; } static void printNums ( int n ) { String str = " " ; printRec ( str , 0 , n ) ; } public static void Main ( ) { int n = 4 ; printNums ( n ) ; } }
Longest Common Substring in an Array of Strings | C # program to find the stem of given list of words ; function to find the stem ( longest common substring ) from the string array ; Determine size of the array ; Take first word from array as reference ; generating all possible substrings of our reference string arr [ 0 ] i . e s ; Check if the generated stem is common to all words ; If current substring is present in all strings and its length is greater than current result ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class stem { public static String findstem ( String [ ] arr ) { int n = arr . Length ; String s = arr [ 0 ] ; int len = s . Length ; String res = " " ; for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i + 1 ; j <= len ; j ++ ) { String stem = s . Substring ( i , j - i ) ; int k = 1 ; for ( k = 1 ; k < n ; k ++ ) if ( ! arr [ k ] . Contains ( stem ) ) break ; if ( k == n && res . Length < stem . Length ) res = stem ; } } return res ; } public static void Main ( String [ ] args ) { String [ ] arr = { " grace " , " graceful " , " disgraceful " , " gracefully " } ; String stems = findstem ( arr ) ; Console . WriteLine ( stems ) ; } }
Make a string from another by deletion and rearrangement of characters | C # program to find if it is possible to make a string from characters present in other string . ; Returns true if it is possible to make s1 from characters present in s2 . ; Count occurrences of all characters present in s2 . . ; For every character , present in s1 , reduce its count if count is more than 0. ; Driver code
using System ; class GFG { static int MAX_CHAR = 256 ; static bool isPossible ( String s1 , String s2 ) { int [ ] count = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < s2 . Length ; i ++ ) count [ ( int ) s2 [ i ] ] ++ ; for ( int i = 0 ; i < s1 . Length ; i ++ ) { if ( count [ ( int ) s1 [ i ] ] == 0 ) return false ; count [ ( int ) s1 [ i ] ] -- ; } return true ; } public static void Main ( ) { string s1 = " GeeksforGeeks " , s2 = " rteksfoGrdsskGeggehes " ; if ( isPossible ( s1 , s2 ) ) Console . WriteLine ( " Possible " ) ; else Console . WriteLine ( " Not ▁ Possible " ) ; } }
Next higher number using atmost one swap operation | C # implementation to find the next higher number using atmost one swap operation ; function to find the next higher number using atmost one swap operation ; to store the index of the largest digit encountered so far from the right ; to store the index of rightmost digit which has a digit greater to it on its right side ; finding the ' index ' of rightmost digit which has a digit greater to it on its right side ; required digit found , store its ' index ' and break ; if no such digit is found which has a larger digit on its right side ; to store the index of the smallest digit greater than the digit at ' index ' and right to it ; finding the index of the smallest digit greater than the digit at ' index ' and right to it ; swapping the digits ; required number ; Driver Code
using System ; class GFG { static String nextHighUsingAtMostOneSwap ( String st ) { char [ ] num = st . ToCharArray ( ) ; int l = num . Length ; int posRMax = l - 1 ; int index = - 1 ; for ( int i = l - 2 ; i >= 0 ; i -- ) { if ( num [ i ] >= num [ posRMax ] ) posRMax = i ; else { index = i ; break ; } } if ( index == - 1 ) return " Not ▁ Possible " ; int greatSmallDgt = - 1 ; for ( int i = l - 1 ; i > index ; i -- ) { if ( num [ i ] > num [ index ] ) { if ( greatSmallDgt == - 1 ) greatSmallDgt = i ; else if ( num [ i ] <= num [ greatSmallDgt ] ) greatSmallDgt = i ; } } char temp = num [ index ] ; num [ index ] = num [ greatSmallDgt ] ; num [ greatSmallDgt ] = temp ; string res = new string ( num ) ; return res ; } public static void Main ( ) { String num = "218765" ; Console . WriteLine ( " Original ▁ number : ▁ " + num ) ; Console . WriteLine ( " Next ▁ higher ▁ number : ▁ " + nextHighUsingAtMostOneSwap ( num ) ) ; } }
Longest substring of vowels | C # program to find the longest substring of vowels . ; Increment current count if s [ i ] is vowel ; check previous value is greater then or not ; Driver code
using System ; class GFG { static bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static int longestVowel ( String str ) { int count = 0 , res = 0 ; char [ ] s = str . ToCharArray ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( isVowel ( s [ i ] ) ) count ++ ; else { res = Math . Max ( res , count ) ; count = 0 ; } } return Math . Max ( res , count ) ; } public static void Main ( ) { String s = " theeare " ; Console . Write ( longestVowel ( s ) ) ; } }
Number of substrings with count of each character as k | C # program to count number of substrings with counts of distinct characters as k . ; Returns true if all values in freq [ ] are either 0 or k . ; Returns count of substrings where frequency of every present character is k ; Pick a starting point ; Initialize all frequencies as 0 for this starting point ; One by one pick ending points ; Increment frequency of current char ; If frequency becomes more than k , we can 't have more substrings  starting with i ; If frequency becomes k , then check other frequencies as well . ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; static bool check ( int [ ] freq , int k ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( freq [ i ] != 0 && freq [ i ] != k ) return false ; return true ; } static int substrings ( String s , int k ) { for ( int i = 0 ; i < s . Length ; i ++ ) { int [ ] freq = new int [ MAX_CHAR ] ; for ( int j = i ; j < s . Length ; j ++ ) { int index = s [ j ] - ' a ' ; freq [ index ] ++ ; if ( freq [ index ] > k ) break ; else if ( freq [ index ] == k && check ( freq , k ) == true ) res ++ ; } } return res ; } public static void Main ( String [ ] args ) { String s = " aabbcc " ; int k = 2 ; Console . WriteLine ( substrings ( s , k ) ) ; s = " aabbc " ; k = 2 ; Console . WriteLine ( substrings ( s , k ) ) ; } }
Longest subsequence where every character appears at | C # program to Find longest subsequence where every character appears at - least k times ; Count frequencies of all characters ; Traverse given string again and print all those characters whose frequency is more than or equal to k . ; Driver code
using System ; public class GFG { static readonly int MAX_CHARS = 26 ; static void longestSubseqWithK ( String str , int k ) { int n = str . Length ; int [ ] freq = new int [ MAX_CHARS ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ str [ i ] - ' a ' ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] - ' a ' ] >= k ) { Console . Write ( str [ i ] ) ; } } } static public void Main ( ) { String str = " geeksforgeeks " ; int k = 2 ; longestSubseqWithK ( str , k ) ; } }
Generating distinct subsequences of a given string in lexicographic order | C # program to print all distinct subsequences of a string . ; Finds and stores result in st for a given string s . ; If current string is not already present . ; Traverse current string , one by one remove every character and recur . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void generate ( HashSet < String > st , String s ) { if ( s . Length == 0 ) { return ; } if ( ! st . Contains ( s ) ) { st . Add ( s ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { String t = s ; t = t . Substring ( 0 , i ) + t . Substring ( i + 1 ) ; generate ( st , t ) ; } } return ; } public static void Main ( String [ ] args ) { String s = " xyz " ; HashSet < String > st = new HashSet < String > ( ) ; generate ( st , s ) ; foreach ( String str in st ) { Console . WriteLine ( str ) ; } } }
Recursive solution to count substrings with same first and last characters | C # program to count substrings with same first and last characters ; Function to count substrings with same first and last characters ; base cases ; Driver code
using System ; class GFG { static int countSubstrs ( string str , int i , int j , int n ) { if ( n == 1 ) return 1 ; if ( n <= 0 ) return 0 ; int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ; if ( str [ i ] == str [ j ] ) res ++ ; return res ; } public static void Main ( ) { string str = " abcab " ; int n = str . Length ; Console . WriteLine ( countSubstrs ( str , 0 , n - 1 , n ) ) ; } }
Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character | C # Program to find minimum number of manipulations required to make two strings identical ; Counts the no of manipulations required ; store the count of character ; iterate though the first String and update count ; iterate through the second string update char_count . if character is not found in char_count then increase count ; Driver code
using System ; public class GFG { static int countManipulations ( string s1 , string s2 ) { int count = 0 ; int [ ] char_count = new int [ 26 ] ; for ( int i = 0 ; i < s1 . Length ; i ++ ) char_count [ s1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < s2 . Length ; i ++ ) char_count [ s2 [ i ] - ' a ' ] -- ; for ( int i = 0 ; i < 26 ; ++ i ) { if ( char_count [ i ] != 0 ) { count += Math . Abs ( char_count [ i ] ) ; } } return count / 2 ; } public static void Main ( ) { string s1 = " ddcf " ; string s2 = " cedk " ; Console . WriteLine ( countManipulations ( s1 , s2 ) ) ; } }
Least number of manipulations needed to ensure two strings have identical characters | C # program to count least number of manipulations to have two strings set of same characters ; return the count of manipulations required ; count the number of different characters in both strings ; check the difference in characters by comparing count arrays ; driver program
using System ; public class GFG { static int MAX_CHAR = 26 ; static int leastCount ( string s1 , string s2 , int n ) { int [ ] count1 = new int [ MAX_CHAR ] ; int [ ] count2 = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { count1 [ s1 [ i ] - ' a ' ] += 1 ; count2 [ s2 [ i ] - ' a ' ] += 1 ; } int res = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( count1 [ i ] != 0 ) { res += Math . Abs ( count1 [ i ] - count2 [ i ] ) ; } } return res ; } static public void Main ( ) { string s1 = " abc " ; string s2 = " cdd " ; int len = s1 . Length ; int res = leastCount ( s1 , s2 , len ) ; Console . WriteLine ( res ) ; } }
Given two strings check which string makes a palindrome first | C # program to check which string makes palindrome first . ; returns winner of two strings ; Count frequencies of characters in both given strings ; Check if there is a character that appears more than once in A and does not appear in B ; Driver Code
using System ; class First_Palin { static int MAX_CHAR = 26 ; static char stringPalindrome ( string A , string B ) { int [ ] countA = new int [ MAX_CHAR ] ; int [ ] countB = new int [ MAX_CHAR ] ; int l1 = A . Length ; int l2 = B . Length ; for ( int i = 0 ; i < l1 ; i ++ ) countA [ A [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) countB [ B [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( ( countA [ i ] > 1 && countB [ i ] == 0 ) ) return ' A ' ; return ' B ' ; } public static void Main ( ) { string a = " abcdea " ; string b = " bcdesg " ; Console . WriteLine ( stringPalindrome ( a , b ) ) ; } }
Print the longest common substring | C # implementation to print the longest common substring ; function to find and print the longest common substring of X [ 0. . m - 1 ] and Y [ 0. . n - 1 ] ; Create a table to store lengths of longest common suffixes of substrings . Note that LCSuff [ i ] [ j ] contains length of longest common suffix of X [ 0. . i - 1 ] and Y [ 0. . j - 1 ] . The first row and first column entries have no logical meaning , they are used only for simplicity of program ; To store length of the longest common substring ; To store the index of the cell which contains the maximum value . This cell 's index helps in building  up the longest common substring from right to left. ; Following steps build LCSuff [ m + 1 ] [ n + 1 ] in bottom up fashion . ; if true , then no common substring exists ; allocate space for the longest common substring ; traverse up diagonally form the ( row , col ) cell until LCSuff [ row ] [ col ] != 0 ; resultStr = X [ row - 1 ] + resultStr ; or Y [ col - 1 ] ; move diagonally up to previous cell ; required longest common substring ; Driver program to test above function
using System ; class GFG { static void printLCSubStr ( String X , String Y , int m , int n ) { int [ , ] LCSuff = new int [ m + 1 , n + 1 ] ; int len = 0 ; int row = 0 , col = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) LCSuff [ i , j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 1 ] ) { LCSuff [ i , j ] = LCSuff [ i - 1 , j - 1 ] + 1 ; if ( len < LCSuff [ i , j ] ) { len = LCSuff [ i , j ] ; row = i ; col = j ; } } else LCSuff [ i , j ] = 0 ; } } if ( len == 0 ) { Console . Write ( " No ▁ Common ▁ Substring " ) ; return ; } String resultStr = " " ; while ( LCSuff [ row , col ] != 0 ) { -- len ; row -- ; col -- ; } Console . WriteLine ( resultStr ) ; } public static void Main ( ) { String X = " OldSite : GeeksforGeeks . org " ; String Y = " NewSite : GeeksQuiz . com " ; int m = X . Length ; int n = Y . Length ; printLCSubStr ( X , Y , m , n ) ; } }
Convert all substrings of length ' k ' from base ' b ' to decimal | Simple C # program to convert all substrings from decimal to given base . ; Saving substring in sub ; Evaluating decimal for current substring and printing it . ; Driver code
using System ; class GFG { static void substringConversions ( String str , int k , int b ) { for ( int i = 0 ; i + k <= str . Length ; i ++ ) { String sub = str . Substring ( i , k ) ; int sum = 0 , counter = 0 ; for ( int j = sub . Length - 1 ; j >= 0 ; j -- ) { sum = ( int ) ( sum + ( ( sub [ j ] - '0' ) * Math . Pow ( b , counter ) ) ) ; counter ++ ; } Console . Write ( sum + " ▁ " ) ; } } public static void Main ( String [ ] args ) { String str = "12212" ; int b = 3 , k = 3 ; substringConversions ( str , b , k ) ; } }
Longest Possible Chunked Palindrome | C # program to find length of longest palindromic chunk ; Here s is the string whose LCP is needed ln is length of string evaluated till now and str is original string ; if there is noting at all ! ! ; if a single letter is left out ; for each length of substring chunk in string ; if left side chunk and right side chunk are same ; Call LCP for the part between the chunks and add 2 to the result . Length of string evaluated till now is increased by ( i + 1 ) * 2 ; Wrapper over LPCRec ( ) ; Driver Code
using System ; class GFG { private static int LPCRec ( string curr_str , int count , int len , string str ) { if ( string . ReferenceEquals ( curr_str , null ) curr_str . Length == 0 ) { return ( 0 ) ; } if ( curr_str . Length <= 1 ) { if ( count != 0 && str . Length - len <= 1 ) { return ( count + 1 ) ; } else { return ( 1 ) ; } } int n = curr_str . Length ; for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( curr_str . Substring ( 0 , i + 1 ) . Equals ( curr_str . Substring ( n - 1 - i , n - ( n - 1 - i ) ) ) ) { return LPCRec ( curr_str . Substring ( i + 1 , ( n - 1 - i ) - ( i + 1 ) ) , count + 2 , len + ( i + 1 ) * 2 , str ) ; } } return count + 1 ; } public static int LPC ( string str ) { return LPCRec ( str , 0 , 0 , str ) ; } public static void Main ( string [ ] args ) { Console . WriteLine ( " V ▁ : ▁ " + LPC ( " V " ) ) ; Console . WriteLine ( " VOLVO ▁ : ▁ " + LPC ( " VOLVO " ) ) ; Console . WriteLine ( " VOLVOV ▁ : ▁ " + LPC ( " VOLVOV " ) ) ; Console . WriteLine ( " ghiabcdefhelloadamhelloabcdefghi ▁ : ▁ " + LPC ( " ghiabcdefhelloadamhelloabcdefghi " ) ) ; Console . WriteLine ( " ghiabcdefhelloadamhelloabcdefghik ▁ : ▁ " + LPC ( " ghiabcdefhelloadamhelloabcdefghik " ) ) ; Console . WriteLine ( " antaprezatepzapreanta ▁ : ▁ " + LPC ( " antaprezatepzapreanta " ) ) ; } }