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
#include <bits/stdc++.h> NEW_LINE using namespace std ; pair < int , int > findFourthVertex ( int n , int m , string s [ ] ) { map < int , int > row , col ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( s [ i ] [ j ] == ' * ' ) { row [ i ] ++ ; col [ j ] ++ ; } int x , y ; for ( auto tm : row ) if ( tm . second == 1 ) x = tm . first ; for ( auto tm : col ) if ( tm . second == 1 ) y = tm . first ; return make_pair ( x + 1 , y + 1 ) ; } int main ( ) { string s [ ] = { " * . * " , " * . . " , " . . . " } ; int n = sizeof ( s ) / sizeof ( s [ 0 ] ) ; int m = s [ 0 ] . length ( ) ; auto rs = findFourthVertex ( n , m , s ) ; cout << rs . first << " ▁ " << rs . second ; }