Print all distinct strings from a given array | C ++ program to implement the above approach ; Function to find the distinct strings from the given array ; Stores distinct strings from the given array ; Traverse the array ; If current string not present into the set ; Insert current string into the set ; Traverse the set DistString ; Print distinct string ; Driver Code ; Stores length of the array
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findDisStr ( vector < string > & arr , int N ) { unordered_set < string > DistString ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! DistString . count ( arr [ i ] ) ) { DistString . insert ( arr [ i ] ) ; } } for ( auto String : DistString ) { cout << String << " ▁ " ; } } int main ( ) { vector < string > arr = { " Geeks " , " For " , " Geeks " , " Code " , " Coder " } ; int N = arr . size ( ) ; findDisStr ( arr , N ) ; return 0 ; }