Print 2 | C # implementation of the above approach ; Function to print the coordinates along with their frequency in ascending order ; Map to store the pairs and their frequencies ; Store the coordinates along with their frequencies ; Driver code
using System ; using System . Collections . Generic ; class GFG { public class store : IComparer < KeyValuePair < int , int > > { public int Compare ( KeyValuePair < int , int > x , KeyValuePair < int , int > y ) { if ( x . Key != y . Key ) { return x . Key . CompareTo ( y . Key ) ; } else { return x . Value . CompareTo ( y . Value ) ; } } } static void Print ( int [ ] x , int [ ] y , int n ) { SortedDictionary < KeyValuePair < int , int > , int > m = new SortedDictionary < KeyValuePair < int , int > , int > ( new store ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { KeyValuePair < int , int > tmp = new KeyValuePair < int , int > ( x [ i ] , y [ i ] ) ; if ( m . ContainsKey ( tmp ) ) { m [ tmp ] ++ ; } else { m [ tmp ] = 1 ; } } foreach ( KeyValuePair < KeyValuePair < int , int > , int > i in m ) { Console . Write ( i . Key . Key + " ▁ " + i . Key . Value + " ▁ " + i . Value + " STRNEWLINE " ) ; } } public static void Main ( string [ ] args ) { int [ ] x = { 1 , 2 , 1 , 1 , 1 } ; int [ ] y = { 1 , 1 , 3 , 1 , 3 } ; int n = x . Length ; Print ( x , y , n ) ; } }