Contiguous unique substrings with the given length L | C ++ implementation ; Function to print the unique sub - string of length n ; set to store the strings ; if the size of the string is equal to 1 then insert ; inserting unique sub - string of length L ; Printing the set of strings ; Driver Code ; Function calling
#include <bits/stdc++.h> NEW_LINE using namespace std ; void result ( string s , int n ) { unordered_set < string > st ; for ( int i = 0 ; i < ( int ) s . size ( ) ; i ++ ) { string ans = " " ; for ( int j = i ; j < ( int ) s . size ( ) ; j ++ ) { ans += s [ j ] ; if ( ans . size ( ) == n ) { st . insert ( ans ) ; break ; } } } for ( auto it : st ) cout << it << " ▁ " ; } int main ( ) { string s = " abca " ; int n = 3 ; result ( s , n ) ; return 0 ; }