Find the coordinates of the fourth vertex of a rectangle with given 3 vertices | C # implementation of the approach ; Function that return the coordinates of the fourth vertex of the rectangle ; Save the coordinates of the given vertices of the rectangle ; 1 - based indexing ; Driver Code
using System ; using System . Collections . Generic ; class GfG { static Pair < int , int > findFourthVertex ( int n , int m , String [ ] s ) { Dictionary < int , int > row = new Dictionary < int , int > ( ) ; Dictionary < int , int > col = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( s [ i ] [ j ] == ' * ' ) { if ( row . ContainsKey ( i ) ) { row [ i ] = row [ i ] + 1 ; } else { row . Add ( i , 1 ) ; } if ( col . ContainsKey ( j ) ) { col [ j ] = col [ j ] + 1 ; } else { col . Add ( j , 1 ) ; } } } } int x = 0 , y = 0 ; foreach ( KeyValuePair < int , int > entry in row ) { if ( entry . Value == 1 ) x = entry . Key ; } foreach ( KeyValuePair < int , int > entry in col ) { if ( entry . Value == 1 ) y = entry . Key ; } Pair < int , int > ans = new Pair < int , int > ( x + 1 , y + 1 ) ; return ans ; } public static void Main ( String [ ] args ) { String [ ] s = { " * . * " , " * . . " , " . . . " } ; int n = s . Length ; int m = s [ 0 ] . Length ; Pair < int , int > rs = findFourthVertex ( n , m , s ) ; Console . WriteLine ( rs . first + " ▁ " + rs . second ) ; } } class Pair < A , B > { public A first ; public B second ; public Pair ( A first , B second ) { this . first = first ; this . second = second ; } }