text: Split a given string into substrings of length K with equal sum of ASCII values | C # program to check if a given string can be split into substrings of size K having an equal sum of ASCII values . ; Function for checking string ; Check if the string can be split into substrings of K length only ; Compute the sum of first substring of length K ; Compute the sum of remaining substrings ; Check if sum is equal to that of the first substring ; Since all sums are not equal , return false ; All sums are equal , Return true ; All substrings cannot be of size K ; Driver code
code: using System ; class GFG { static bool check ( string str , int K ) { if ( str . Length % K == 0 ) { int sum = 0 , i ; for ( i = 0 ; i < K ; i ++ ) { sum += str [ i ] ; } for ( int j = i ; j < str . Length ; j += K ) { int s_comp = 0 ; for ( int p = j ; p < j + K ; p ++ ) s_comp += str [ p ] ; if ( s_comp != sum ) return false ; } return true ; } return false ; } public static void Main ( string [ ] args ) { int K = 3 ; string str = " abdcbbdba " ; if ( check ( str , K ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }