text: Contiguous subsegments of a string having distinct subsequent characters | C ++ implementation of the approach ; Function that prints the segments ; New array for every iteration ; Check if iterator points to end or not ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void sub_segments ( string str , int n ) { int l = str . length ( ) ; for ( int x = 0 ; x < l ; x += n ) { string newlist = str . substr ( x , n ) ; list < char > arr ; list < char > :: iterator it ; for ( auto y : newlist ) { it = find ( arr . begin ( ) , arr . end ( ) , y ) ; if ( it == arr . end ( ) ) arr . push_back ( y ) ; } for ( auto y : arr ) cout << y ; cout << endl ; } } int main ( ) { string str = " geeksforgeeksgfg " ; int n = 4 ; sub_segments ( str , n ) ; }