Count pairs of similar rectangles possible from a given array |  ; Get the count of all pairs of similar rectangles ; Initialize the result value and map to store the ratio to the rectangles ; Calculate the rectangular ratio and save them ; Calculate pairs of similar rectangles from its common ratio ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static int getCount ( int rows , int columns , int [ , ] sides ) { int res = 0 ; Dictionary < double , int > ratio = new Dictionary < double , int > ( ) ; for ( int i = 0 ; i < rows ; i ++ ) { double rectRatio = ( double ) sides [ i , 0 ] / sides [ i , 1 ] ; if ( ! ratio . ContainsKey ( rectRatio ) ) { ratio [ rectRatio ] = 0 ; } ratio [ rectRatio ] = ratio [ rectRatio ] + 1 ; } foreach ( KeyValuePair < double , int > p in ratio ) { int val = p . Value ; if ( val > 1 ) { res += ( val * ( val - 1 ) ) / 2 ; } } return res ; } public static void Main ( string [ ] args ) { int [ , ] A = { { 4 , 8 } , { 10 , 20 } , { 15 , 30 } , { 3 , 6 } } ; int columns = 2 ; int rows = 4 ; Console . WriteLine ( getCount ( rows , columns , A ) ) ; } }