PROBLEM STATEMENT
A skew symmetric matrix M satisfies MT = -M, where MT denotes the transpose of the matrix M and -M denotes the matrix obtained by multiplying each entry of M by -1. The transpose of a matrix M is obtained by replacing the element in the i'th row and j'th column of M with the element in the j'th row and i'th column of M. Note that this requires the diagonal elements of a skew-symmetric matrix to be equal to 0.
Create a class SkewSymmetric which contains a method minChanges. The method will take a
two dimensional matrix M of integers.
The j'th number in the i'th element of M represents the value at row i and column j of the matrix. The method should return the minimum number of values in M that must be changed such that the resulting matrix is skew symmetric.
You must also write a main procedure that will take the rows of the matrix
as command line arguments. Each row will consist of a string of n
integers. You will need to use a Scanner object to extract the integers from
the strings and insert them into a matrix, which you will then pass to
minChanges.
DEFINITION
Class:SkewSymmetric
Method:minChanges
Parameters:int[][] matrix;
Returns:int
Method signature:int minChanges(int[][] M)
CONSTRAINTS
- Each element of M will be a single space separated list of exactly n integers, where n is the number of elements in M.
- Each integer in M will be between -99 and 99 inclusive, with no extra leading zeros.
- The integer zero will be represented as '0' (quotes for clarity) only, and not '-0' (quotes for clarity) in M.
EXAMPLES
0) java SkewSymmetric "1 2 8" "-2 1 0" "3 99 3"
Returns: 5
One possible skew-symmetric matrix obtained by changing 5 elements in M is:
0 2 -3
-2 0 -99
3 99 0
Note that the diagonal elements must be 0.
1) java SkewSymmetric "0 1 1 1 1 1" "-1 0 1 1 1 1" "-1 -1 0 1 1 1"
"-1 -1 -1 0 1 1" "-1 -1 -1 -1 0 1" "0 0 0 0 0 0"
Returns: 5
2) java SkewSymmetric "0 0 0 0" "0 0 0 0" "0 0 0 0" "0 0 0 0"
Returns: 0
3) java SkewSymmetric "1 0" "0 1"
Returns: 2