Check if given string can be split into four distinct strings | C # program to check if we can break a string into four distinct strings . ; Return true if both strings are equal ; Return if the given string can be split or not . ; Brute Force ; Making 4 string from the given string ; Checking if they are distinct or not . ; Driver code
using System ; class GFG { public static Boolean strcheck ( String s1 , String s2 ) { if ( s1 . CompareTo ( s2 ) != 0 ) return false ; return true ; } public static Boolean check ( String s ) { if ( s . Length >= 10 ) return true ; for ( int i = 1 ; i < s . Length ; i ++ ) { for ( int j = i + 1 ; j < s . Length ; j ++ ) { for ( int k = j + 1 ; k < s . Length ; k ++ ) { String s1 = " " , s2 = " " , s3 = " " , s4 = " " ; try { s1 = s . Substring ( 0 , i ) ; s2 = s . Substring ( i , j - i ) ; s3 = s . Substring ( j , k - j ) ; s4 = s . Substring ( k , s . Length - k ) ; } catch ( Exception e ) { } if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ; } } } return false ; } public static void Main ( String [ ] args ) { String str = " aaabb " ; if ( check ( str ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }