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 if the given string can be split or not . ; We can always break a string of size 10 or more into four distinct strings . ; Brute Force ; Making 4 string from the given string ; Checking if they are distinct or not . ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( string s ) { if ( s . size ( ) >= 10 ) return true ; for ( int i = 1 ; i < s . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < s . size ( ) ; j ++ ) { for ( int k = j + 1 ; k < s . size ( ) ; k ++ ) { string s1 = s . substr ( 0 , i ) ; string s2 = s . substr ( i , j - i ) ; string s3 = s . substr ( j , k - j ) ; string s4 = s . substr ( k , s . size ( ) - k ) ; if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ; } } } return false ; } int main ( ) { string str = " aaabb " ; ( check ( str ) ) ? ( cout << " Yes " << endl ) : ( cout << " No " << endl ) ; return 0 ; }