Check if a string can be split into two substrings such that one substring is a substring of the other | C ++ program to implement the above approach ; Function to check if a string can be divided into two substrings such that one substring is substring of the other ; Store the last character of S ; Traverse the characters at indices [ 0 , N - 2 ] ; Check if the current character is equal to the last character ; If true , set f = 1 ; Break out of the loop ; Driver Code ; Given string , S ; Store the size of S ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void splitString ( string S , int N ) { char c = S [ N - 1 ] ; int f = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S [ i ] == c ) { f = 1 ; break ; } } if ( f ) cout << " Yes " ; else cout << " No " ; } int main ( ) { string S = " abcdab " ; int N = S . size ( ) ; splitString ( S , N ) ; return 0 ; }