Modify array of strings by replacing characters repeating in the same or remaining strings | C ++ program for the above approach ; Function to remove duplicate characters across the strings ; Stores distinct characters ; Size of the array ; Stores the list of modified strings ; Traverse the array ; Stores the modified string ; Iterate over the characters of the modified string ; If character is already present ; Insert character into the Set ; Print the list of modified strings ; Print each string ; Driver Code ; Given array of strings ; Function Call to modify the given array of strings
#include <bits/stdc++.h> NEW_LINE using namespace std ; void removeDuplicateCharacters ( vector < string > arr ) { unordered_set < char > cset ; int n = arr . size ( ) ; vector < string > out ; for ( auto str : arr ) { string out_curr = " " ; for ( auto ch : str ) { if ( cset . find ( ch ) != cset . end ( ) ) continue ; out_curr += ch ; cset . insert ( ch ) ; } if ( out_curr . size ( ) ) out . push_back ( out_curr ) ; } for ( int i = 0 ; i < out . size ( ) ; i ++ ) { cout << out [ i ] << " ▁ " ; } } int main ( ) { vector < string > arr = { " Geeks " , " For " , " Geeks " , " Post " } ; removeDuplicateCharacters ( arr ) ; }