Append digits to the end of duplicate strings to make all strings in an array unique | C # program for the above approach ; Function to replace duplicate strings by alphanumeric strings to make all strings in the array unique ; Store the frequency of strings ; Iterate over the array ; For the first occurrence , update the frequency count ; Otherwise ; Append frequency count to end of the string ; Print the modified array ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void replaceDuplicates ( string [ ] names ) { Dictionary < string , int > hash = new Dictionary < string , int > ( ) ; for ( int i = 0 ; i < names . Length ; i ++ ) { if ( ! hash . ContainsKey ( names [ i ] ) ) hash [ names [ i ] ] = 1 ; else { int count = hash [ names [ i ] ] ; hash [ names [ i ] ] += 1 ; names [ i ] += count . ToString ( ) ; } } for ( int i = 0 ; i < names . Length ; i ++ ) { Console . Write ( names [ i ] + ' ▁ ' ) ; } } public static void Main ( ) { string [ ] str = { " aa " , " bb " , " cc " , " bb " , " aa " , " aa " , " aa " } ; replaceDuplicates ( str ) ; } }