Find number of transformation to make two Matrix Equal | C # program to find number of countOpsation to make two matrix equals ; Update matrix A [ ] [ ] so that only A [ ] [ ] has to be countOpsed ; Check necessary condition for condition for existence of full countOpsation ; If countOpsation is possible calculate total countOpsation ; Driver code
using System ; class GFG { static int countOps ( int [ , ] A , int [ , ] B , int m , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) A [ i , j ] -= B [ i , j ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j < m ; j ++ ) if ( A [ i , j ] - A [ i , 0 ] - A [ 0 , j ] + A [ 0 , 0 ] != 0 ) return - 1 ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) result += Math . Abs ( A [ i , 0 ] ) ; for ( int j = 0 ; j < m ; j ++ ) result += Math . Abs ( A [ 0 , j ] - A [ 0 , 0 ] ) ; return ( result ) ; } public static void Main ( ) { int [ , ] A = { { 1 , 1 , 1 } , { 1 , 1 , 1 } , { 1 , 1 , 1 } } ; int [ , ] B = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; Console . Write ( countOps ( A , B , 3 , 3 ) ) ; } }